blob: 5eb17f15c906f8a085f43161163a0668508c6745 [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001/*
Bin Meng65db0c92015-01-20 11:25:44 +08002 * U-Boot - x86 Startup Code
wdenk591dda52002-11-18 00:14:45 +00003 *
Graeme Russ45fc1d82011-04-13 19:43:26 +10004 * (C) Copyright 2008-2011
5 * Graeme Russ, <graeme.russ@gmail.com>
6 *
7 * (C) Copyright 2002,2003
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02008 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenk591dda52002-11-18 00:14:45 +00009 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
wdenk591dda52002-11-18 00:14:45 +000011 */
12
Graeme Russ80ccbac2010-10-07 20:03:30 +110013#include <asm/global_data.h>
Graeme Russ93efcb22011-02-12 15:11:32 +110014#include <asm/processor-flags.h>
wdenk591dda52002-11-18 00:14:45 +000015
16#define BOOT_SEG 0xffff0000 /* linear segment of boot code */
17#define a32 .byte 0x67;
18#define o32 .byte 0x66;
19
20.section .start16, "ax"
21.code16
22.globl start16
wdenk57b2d802003-06-27 21:31:46 +000023start16:
Simon Glass1f4476c2014-11-06 13:20:10 -070024 /* Save BIST */
25 movl %eax, %ecx
26
Gabe Blackef899322012-11-03 11:41:28 +000027 /* Set the Cold Boot / Hard Reset flag */
28 movl $GD_FLG_COLD_BOOT, %ebx
29
Simon Glass727c4142014-11-06 13:20:03 -070030 xorl %eax, %eax
Bin Meng65db0c92015-01-20 11:25:44 +080031 movl %eax, %cr3 /* Invalidate TLB */
Simon Glass727c4142014-11-06 13:20:03 -070032
Simon Glasscbfd7ff2014-11-06 13:20:01 -070033 /* Turn off cache (this might require a 486-class CPU) */
Wolfgang Denka1be4762008-05-20 16:00:29 +020034 movl %cr0, %eax
Ondrej Kupka19c114a2011-09-30 21:05:11 +110035 orl $(X86_CR0_NW | X86_CR0_CD), %eax
Wolfgang Denka1be4762008-05-20 16:00:29 +020036 movl %eax, %cr0
wdenk57b2d802003-06-27 21:31:46 +000037 wbinvd
38
Graeme Russ59da5a52010-04-24 00:05:43 +100039 /* load the temporary Global Descriptor Table */
Graeme Russ4fdcc422010-08-22 16:25:59 +100040o32 cs lidt idt_ptr
Wolfgang Denka1be4762008-05-20 16:00:29 +020041o32 cs lgdt gdt_ptr
wdenk591dda52002-11-18 00:14:45 +000042
wdenk591dda52002-11-18 00:14:45 +000043 /* Now, we enter protected mode */
Wolfgang Denka1be4762008-05-20 16:00:29 +020044 movl %cr0, %eax
Graeme Russ93efcb22011-02-12 15:11:32 +110045 orl $X86_CR0_PE, %eax
Wolfgang Denka1be4762008-05-20 16:00:29 +020046 movl %eax, %cr0
wdenk57b2d802003-06-27 21:31:46 +000047
wdenk591dda52002-11-18 00:14:45 +000048 /* Flush the prefetch queue */
Wolfgang Denka1be4762008-05-20 16:00:29 +020049 jmp ff
wdenk591dda52002-11-18 00:14:45 +000050ff:
Simon Glass1f4476c2014-11-06 13:20:10 -070051
Bin Meng65db0c92015-01-20 11:25:44 +080052 /* Finally restore BIST and jump to the 32-bit initialization code */
wdenk57b2d802003-06-27 21:31:46 +000053 movw $code32start, %ax
Graeme Russ3e6ec382010-10-07 20:03:21 +110054 movw %ax, %bp
Simon Glass1f4476c2014-11-06 13:20:10 -070055 movl %ecx, %eax
wdenk591dda52002-11-18 00:14:45 +000056o32 cs ljmp *(%bp)
57
58 /* 48-bit far pointer */
59code32start:
Wolfgang Denka1be4762008-05-20 16:00:29 +020060 .long _start /* offset */
61 .word 0x10 /* segment */
wdenk591dda52002-11-18 00:14:45 +000062
Graeme Russ4fdcc422010-08-22 16:25:59 +100063idt_ptr:
64 .word 0 /* limit */
65 .long 0 /* base */
66
Bin Meng65db0c92015-01-20 11:25:44 +080067 /*
68 * The following Global Descriptor Table is just enough to get us into
69 * 'Flat Protected Mode' - It will be discarded as soon as the final
70 * GDT is setup in a safe location in RAM
71 */
wdenk591dda52002-11-18 00:14:45 +000072gdt_ptr:
Bin Meng0f39bc02014-10-16 22:58:35 +080073 .word 0x1f /* limit (31 bytes = 4 GDT entries - 1) */
Bin Menga3c9fb02015-06-07 11:33:13 +080074 .long BOOT_SEG + gdt_rom /* base */
wdenk591dda52002-11-18 00:14:45 +000075
Bin Meng65db0c92015-01-20 11:25:44 +080076 /* Some CPUs are picky about GDT alignment... */
77 .align 16
Bin Menga3c9fb02015-06-07 11:33:13 +080078.globl gdt_rom
79gdt_rom:
Graeme Russaf3f2c82011-12-19 14:26:18 +110080 /*
81 * The GDT table ...
wdenk591dda52002-11-18 00:14:45 +000082 *
Wolfgang Denka1be4762008-05-20 16:00:29 +020083 * Selector Type
84 * 0x00 NULL
85 * 0x08 Unused
wdenk57b2d802003-06-27 21:31:46 +000086 * 0x10 32bit code
wdenk591dda52002-11-18 00:14:45 +000087 * 0x18 32bit data/stack
wdenk591dda52002-11-18 00:14:45 +000088 */
Graeme Russaf3f2c82011-12-19 14:26:18 +110089 /* The NULL Desciptor - Mandatory */
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 */
wdenk591dda52002-11-18 00:14:45 +000096
Graeme Russaf3f2c82011-12-19 14:26:18 +110097 /* Unused Desciptor - (matches Linux) */
98 .word 0x0000 /* limit_low */
99 .word 0x0000 /* base_low */
100 .byte 0x00 /* base_middle */
101 .byte 0x00 /* access */
102 .byte 0x00 /* flags + limit_high */
103 .byte 0x00 /* base_high */
wdenk591dda52002-11-18 00:14:45 +0000104
Graeme Russaf3f2c82011-12-19 14:26:18 +1100105 /*
106 * The Code Segment Descriptor:
107 * - Base = 0x00000000
108 * - Size = 4GB
109 * - Access = Present, Ring 0, Exec (Code), Readable
110 * - Flags = 4kB Granularity, 32-bit
111 */
112 .word 0xffff /* limit_low */
113 .word 0x0000 /* base_low */
114 .byte 0x00 /* base_middle */
115 .byte 0x9b /* access */
116 .byte 0xcf /* flags + limit_high */
117 .byte 0x00 /* base_high */
wdenk591dda52002-11-18 00:14:45 +0000118
Graeme Russaf3f2c82011-12-19 14:26:18 +1100119 /*
120 * The Data Segment Descriptor:
121 * - Base = 0x00000000
122 * - Size = 4GB
123 * - Access = Present, Ring 0, Non-Exec (Data), Writable
124 * - Flags = 4kB Granularity, 32-bit
125 */
126 .word 0xffff /* limit_low */
127 .word 0x0000 /* base_low */
128 .byte 0x00 /* base_middle */
129 .byte 0x93 /* access */
130 .byte 0xcf /* flags + limit_high */
131 .byte 0x00 /* base_high */