1/* SPDX-License-Identifier: GPL-2.0+ */ 2/* 3 * U-Boot - x86 Startup Code 4 * 5 * (C) Copyright 2008-2011 6 * Graeme Russ, <graeme.russ@gmail.com> 7 * 8 * (C) Copyright 2002,2003 9 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> 10 */ 11 12#include <asm/global_data.h> 13#include <asm/processor-flags.h> 14 15#define BOOT_SEG 0xffff0000 /* linear segment of boot code */ 16 17.section .start16, "ax" 18.code16 19.globl start16 20start16: 21 /* Save BIST */ 22 movl %eax, %ecx 23 24 xorl %eax, %eax 25 movl %eax, %cr3 /* Invalidate TLB */ 26 27 /* Turn off cache (this might require a 486-class CPU) */ 28 movl %cr0, %eax 29 orl $(X86_CR0_NW | X86_CR0_CD), %eax 30 movl %eax, %cr0 31 wbinvd 32 33 /* load the temporary Global Descriptor Table */ 34data32 cs lidt idt_ptr 35data32 cs lgdt gdt_ptr 36 37 /* Now, we enter protected mode */ 38 movl %cr0, %eax 39 orl $X86_CR0_PE, %eax 40 movl %eax, %cr0 41 42 /* Flush the prefetch queue */ 43 jmp ff 44ff: 45 46 /* Finally restore BIST and jump to the 32-bit initialization code */ 47 movl %ecx, %eax 48data32 cs ljmp *code32start 49 50 /* 48-bit far pointer */ 51code32start: 52 .long _start /* offset */ 53 .word 0x10 /* segment */ 54 55idt_ptr: 56 .word 0 /* limit */ 57 .long 0 /* base */ 58 59 /* 60 * The following Global Descriptor Table is just enough to get us into 61 * 'Flat Protected Mode' - It will be discarded as soon as the final 62 * GDT is setup in a safe location in RAM 63 */ 64gdt_ptr: 65 .word 0x1f /* limit (31 bytes = 4 GDT entries - 1) */ 66 .long BOOT_SEG + gdt_rom /* base */ 67 68 /* Some CPUs are picky about GDT alignment... */ 69 .align 16 70.globl gdt_rom 71gdt_rom: 72 /* 73 * The GDT table ... 74 * 75 * Selector Type 76 * 0x00 NULL 77 * 0x08 Unused 78 * 0x10 32bit code 79 * 0x18 32bit data/stack 80 */ 81 /* The NULL Desciptor - Mandatory */ 82 .word 0x0000 /* limit_low */ 83 .word 0x0000 /* base_low */ 84 .byte 0x00 /* base_middle */ 85 .byte 0x00 /* access */ 86 .byte 0x00 /* flags + limit_high */ 87 .byte 0x00 /* base_high */ 88 89 /* Unused Desciptor - (matches Linux) */ 90 .word 0x0000 /* limit_low */ 91 .word 0x0000 /* base_low */ 92 .byte 0x00 /* base_middle */ 93 .byte 0x00 /* access */ 94 .byte 0x00 /* flags + limit_high */ 95 .byte 0x00 /* base_high */ 96 97 /* 98 * The Code Segment Descriptor: 99 * - Base = 0x00000000 100 * - Size = 4GB 101 * - Access = Present, Ring 0, Exec (Code), Readable 102 * - Flags = 4kB Granularity, 32-bit 103 */ 104 .word 0xffff /* limit_low */ 105 .word 0x0000 /* base_low */ 106 .byte 0x00 /* base_middle */ 107 .byte 0x9b /* access */ 108 .byte 0xcf /* flags + limit_high */ 109 .byte 0x00 /* base_high */ 110 111 /* 112 * The Data Segment Descriptor: 113 * - Base = 0x00000000 114 * - Size = 4GB 115 * - Access = Present, Ring 0, Non-Exec (Data), Writable 116 * - Flags = 4kB Granularity, 32-bit 117 */ 118 .word 0xffff /* limit_low */ 119 .word 0x0000 /* base_low */ 120 .byte 0x00 /* base_middle */ 121 .byte 0x93 /* access */ 122 .byte 0xcf /* flags + limit_high */ 123 .byte 0x00 /* base_high */ 124