blob: 54f4ff6662a8d8999311be3e7553882b1b245c2a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
wdenk2262cfe2002-11-18 00:14:45 +00002/*
Bin Mengfea1c472015-01-20 11:25:44 +08003 * U-Boot - x86 Startup Code
wdenk2262cfe2002-11-18 00:14:45 +00004 *
Graeme Russdbf71152011-04-13 19:43:26 +10005 * (C) Copyright 2008-2011
6 * Graeme Russ, <graeme.russ@gmail.com>
7 *
8 * (C) Copyright 2002,2003
Albert ARIBAUDfa82f872011-08-04 18:45:45 +02009 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenk2262cfe2002-11-18 00:14:45 +000010 */
11
Graeme Russc81b26b2010-10-07 20:03:30 +110012#include <asm/global_data.h>
Graeme Russ0c24c9c2011-02-12 15:11:32 +110013#include <asm/processor-flags.h>
wdenk2262cfe2002-11-18 00:14:45 +000014
15#define BOOT_SEG 0xffff0000 /* linear segment of boot code */
wdenk2262cfe2002-11-18 00:14:45 +000016
17.section .start16, "ax"
18.code16
19.globl start16
wdenk8bde7f72003-06-27 21:31:46 +000020start16:
Simon Glassf67cd512014-11-06 13:20:10 -070021 /* Save BIST */
22 movl %eax, %ecx
23
Simon Glass3c006952014-11-06 13:20:03 -070024 xorl %eax, %eax
Bin Mengfea1c472015-01-20 11:25:44 +080025 movl %eax, %cr3 /* Invalidate TLB */
Simon Glass3c006952014-11-06 13:20:03 -070026
Simon Glass85d87322014-11-06 13:20:01 -070027 /* Turn off cache (this might require a 486-class CPU) */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020028 movl %cr0, %eax
Ondrej Kupka7b3d5382011-09-30 21:05:11 +110029 orl $(X86_CR0_NW | X86_CR0_CD), %eax
Wolfgang Denk53677ef2008-05-20 16:00:29 +020030 movl %eax, %cr0
Andy Shevchenkofa97ca12020-02-17 17:30:12 +020031 wbinvd
wdenk8bde7f72003-06-27 21:31:46 +000032
Graeme Russc14a3662010-04-24 00:05:43 +100033 /* load the temporary Global Descriptor Table */
Masahiro Yamada0d915a92019-12-03 14:20:49 +090034data32 cs lidt idt_ptr
35data32 cs lgdt gdt_ptr
wdenk2262cfe2002-11-18 00:14:45 +000036
wdenk2262cfe2002-11-18 00:14:45 +000037 /* Now, we enter protected mode */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020038 movl %cr0, %eax
Graeme Russ0c24c9c2011-02-12 15:11:32 +110039 orl $X86_CR0_PE, %eax
Wolfgang Denk53677ef2008-05-20 16:00:29 +020040 movl %eax, %cr0
wdenk8bde7f72003-06-27 21:31:46 +000041
wdenk2262cfe2002-11-18 00:14:45 +000042 /* Flush the prefetch queue */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020043 jmp ff
wdenk2262cfe2002-11-18 00:14:45 +000044ff:
Simon Glassf67cd512014-11-06 13:20:10 -070045
Bin Mengfea1c472015-01-20 11:25:44 +080046 /* Finally restore BIST and jump to the 32-bit initialization code */
Simon Glassf67cd512014-11-06 13:20:10 -070047 movl %ecx, %eax
Masahiro Yamada90ab3112019-12-03 14:28:58 +090048data32 cs ljmp *code32start
wdenk2262cfe2002-11-18 00:14:45 +000049
50 /* 48-bit far pointer */
51code32start:
Wolfgang Denk53677ef2008-05-20 16:00:29 +020052 .long _start /* offset */
53 .word 0x10 /* segment */
wdenk2262cfe2002-11-18 00:14:45 +000054
Graeme Russ797960f2010-08-22 16:25:59 +100055idt_ptr:
56 .word 0 /* limit */
57 .long 0 /* base */
58
Bin Mengfea1c472015-01-20 11:25:44 +080059 /*
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 */
wdenk2262cfe2002-11-18 00:14:45 +000064gdt_ptr:
Bin Meng35d4fed2014-10-16 22:58:35 +080065 .word 0x1f /* limit (31 bytes = 4 GDT entries - 1) */
Bin Meng002610f2015-06-07 11:33:13 +080066 .long BOOT_SEG + gdt_rom /* base */
wdenk2262cfe2002-11-18 00:14:45 +000067
Bin Mengfea1c472015-01-20 11:25:44 +080068 /* Some CPUs are picky about GDT alignment... */
69 .align 16
Bin Meng002610f2015-06-07 11:33:13 +080070.globl gdt_rom
71gdt_rom:
Graeme Russ58c7a672011-12-19 14:26:18 +110072 /*
73 * The GDT table ...
wdenk2262cfe2002-11-18 00:14:45 +000074 *
Wolfgang Denk53677ef2008-05-20 16:00:29 +020075 * Selector Type
76 * 0x00 NULL
77 * 0x08 Unused
wdenk8bde7f72003-06-27 21:31:46 +000078 * 0x10 32bit code
wdenk2262cfe2002-11-18 00:14:45 +000079 * 0x18 32bit data/stack
wdenk2262cfe2002-11-18 00:14:45 +000080 */
Graeme Russ58c7a672011-12-19 14:26:18 +110081 /* 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 */
wdenk2262cfe2002-11-18 00:14:45 +000088
Graeme Russ58c7a672011-12-19 14:26:18 +110089 /* 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 */
wdenk2262cfe2002-11-18 00:14:45 +000096
Graeme Russ58c7a672011-12-19 14:26:18 +110097 /*
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 */
wdenk2262cfe2002-11-18 00:14:45 +0000110
Graeme Russ58c7a672011-12-19 14:26:18 +1100111 /*
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 */