blob: dd659278ffeec7ade18e64d1018597c6dd3bb931 [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 */
16#define a32 .byte 0x67;
17#define o32 .byte 0x66;
18
19.section .start16, "ax"
20.code16
21.globl start16
wdenk8bde7f72003-06-27 21:31:46 +000022start16:
Simon Glassf67cd512014-11-06 13:20:10 -070023 /* Save BIST */
24 movl %eax, %ecx
25
Gabe Black91d82a22012-11-03 11:41:28 +000026 /* Set the Cold Boot / Hard Reset flag */
27 movl $GD_FLG_COLD_BOOT, %ebx
28
Simon Glass3c006952014-11-06 13:20:03 -070029 xorl %eax, %eax
Bin Mengfea1c472015-01-20 11:25:44 +080030 movl %eax, %cr3 /* Invalidate TLB */
Simon Glass3c006952014-11-06 13:20:03 -070031
Simon Glass85d87322014-11-06 13:20:01 -070032 /* Turn off cache (this might require a 486-class CPU) */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020033 movl %cr0, %eax
Ondrej Kupka7b3d5382011-09-30 21:05:11 +110034 orl $(X86_CR0_NW | X86_CR0_CD), %eax
Wolfgang Denk53677ef2008-05-20 16:00:29 +020035 movl %eax, %cr0
wdenk8bde7f72003-06-27 21:31:46 +000036 wbinvd
37
Graeme Russc14a3662010-04-24 00:05:43 +100038 /* load the temporary Global Descriptor Table */
Graeme Russ797960f2010-08-22 16:25:59 +100039o32 cs lidt idt_ptr
Wolfgang Denk53677ef2008-05-20 16:00:29 +020040o32 cs lgdt gdt_ptr
wdenk2262cfe2002-11-18 00:14:45 +000041
wdenk2262cfe2002-11-18 00:14:45 +000042 /* Now, we enter protected mode */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020043 movl %cr0, %eax
Graeme Russ0c24c9c2011-02-12 15:11:32 +110044 orl $X86_CR0_PE, %eax
Wolfgang Denk53677ef2008-05-20 16:00:29 +020045 movl %eax, %cr0
wdenk8bde7f72003-06-27 21:31:46 +000046
wdenk2262cfe2002-11-18 00:14:45 +000047 /* Flush the prefetch queue */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020048 jmp ff
wdenk2262cfe2002-11-18 00:14:45 +000049ff:
Simon Glassf67cd512014-11-06 13:20:10 -070050
Bin Mengfea1c472015-01-20 11:25:44 +080051 /* Finally restore BIST and jump to the 32-bit initialization code */
wdenk8bde7f72003-06-27 21:31:46 +000052 movw $code32start, %ax
Graeme Russ8ffb2e82010-10-07 20:03:21 +110053 movw %ax, %bp
Simon Glassf67cd512014-11-06 13:20:10 -070054 movl %ecx, %eax
wdenk2262cfe2002-11-18 00:14:45 +000055o32 cs ljmp *(%bp)
56
57 /* 48-bit far pointer */
58code32start:
Wolfgang Denk53677ef2008-05-20 16:00:29 +020059 .long _start /* offset */
60 .word 0x10 /* segment */
wdenk2262cfe2002-11-18 00:14:45 +000061
Graeme Russ797960f2010-08-22 16:25:59 +100062idt_ptr:
63 .word 0 /* limit */
64 .long 0 /* base */
65
Bin Mengfea1c472015-01-20 11:25:44 +080066 /*
67 * The following Global Descriptor Table is just enough to get us into
68 * 'Flat Protected Mode' - It will be discarded as soon as the final
69 * GDT is setup in a safe location in RAM
70 */
wdenk2262cfe2002-11-18 00:14:45 +000071gdt_ptr:
Bin Meng35d4fed2014-10-16 22:58:35 +080072 .word 0x1f /* limit (31 bytes = 4 GDT entries - 1) */
Bin Meng002610f2015-06-07 11:33:13 +080073 .long BOOT_SEG + gdt_rom /* base */
wdenk2262cfe2002-11-18 00:14:45 +000074
Bin Mengfea1c472015-01-20 11:25:44 +080075 /* Some CPUs are picky about GDT alignment... */
76 .align 16
Bin Meng002610f2015-06-07 11:33:13 +080077.globl gdt_rom
78gdt_rom:
Graeme Russ58c7a672011-12-19 14:26:18 +110079 /*
80 * The GDT table ...
wdenk2262cfe2002-11-18 00:14:45 +000081 *
Wolfgang Denk53677ef2008-05-20 16:00:29 +020082 * Selector Type
83 * 0x00 NULL
84 * 0x08 Unused
wdenk8bde7f72003-06-27 21:31:46 +000085 * 0x10 32bit code
wdenk2262cfe2002-11-18 00:14:45 +000086 * 0x18 32bit data/stack
wdenk2262cfe2002-11-18 00:14:45 +000087 */
Graeme Russ58c7a672011-12-19 14:26:18 +110088 /* The NULL Desciptor - Mandatory */
89 .word 0x0000 /* limit_low */
90 .word 0x0000 /* base_low */
91 .byte 0x00 /* base_middle */
92 .byte 0x00 /* access */
93 .byte 0x00 /* flags + limit_high */
94 .byte 0x00 /* base_high */
wdenk2262cfe2002-11-18 00:14:45 +000095
Graeme Russ58c7a672011-12-19 14:26:18 +110096 /* Unused Desciptor - (matches Linux) */
97 .word 0x0000 /* limit_low */
98 .word 0x0000 /* base_low */
99 .byte 0x00 /* base_middle */
100 .byte 0x00 /* access */
101 .byte 0x00 /* flags + limit_high */
102 .byte 0x00 /* base_high */
wdenk2262cfe2002-11-18 00:14:45 +0000103
Graeme Russ58c7a672011-12-19 14:26:18 +1100104 /*
105 * The Code Segment Descriptor:
106 * - Base = 0x00000000
107 * - Size = 4GB
108 * - Access = Present, Ring 0, Exec (Code), Readable
109 * - Flags = 4kB Granularity, 32-bit
110 */
111 .word 0xffff /* limit_low */
112 .word 0x0000 /* base_low */
113 .byte 0x00 /* base_middle */
114 .byte 0x9b /* access */
115 .byte 0xcf /* flags + limit_high */
116 .byte 0x00 /* base_high */
wdenk2262cfe2002-11-18 00:14:45 +0000117
Graeme Russ58c7a672011-12-19 14:26:18 +1100118 /*
119 * The Data Segment Descriptor:
120 * - Base = 0x00000000
121 * - Size = 4GB
122 * - Access = Present, Ring 0, Non-Exec (Data), Writable
123 * - Flags = 4kB Granularity, 32-bit
124 */
125 .word 0xffff /* limit_low */
126 .word 0x0000 /* base_low */
127 .byte 0x00 /* base_middle */
128 .byte 0x93 /* access */
129 .byte 0xcf /* flags + limit_high */
130 .byte 0x00 /* base_high */