blob: 474efe4df5f426ba799499cc775f87752b6f5c51 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
wdenk591dda52002-11-18 00:14:45 +00002/*
Bin Meng65db0c92015-01-20 11:25:44 +08003 * U-Boot - x86 Startup Code
wdenk591dda52002-11-18 00:14:45 +00004 *
Graeme Russ45fc1d82011-04-13 19:43:26 +10005 * (C) Copyright 2008-2011
6 * Graeme Russ, <graeme.russ@gmail.com>
7 *
8 * (C) Copyright 2002,2003
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02009 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenk591dda52002-11-18 00:14:45 +000010 */
11
Graeme Russ80ccbac2010-10-07 20:03:30 +110012#include <asm/global_data.h>
Graeme Russ93efcb22011-02-12 15:11:32 +110013#include <asm/processor-flags.h>
wdenk591dda52002-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
wdenk57b2d802003-06-27 21:31:46 +000022start16:
Simon Glass1f4476c2014-11-06 13:20:10 -070023 /* Save BIST */
24 movl %eax, %ecx
25
Simon Glass727c4142014-11-06 13:20:03 -070026 xorl %eax, %eax
Bin Meng65db0c92015-01-20 11:25:44 +080027 movl %eax, %cr3 /* Invalidate TLB */
Simon Glass727c4142014-11-06 13:20:03 -070028
Simon Glasscbfd7ff2014-11-06 13:20:01 -070029 /* Turn off cache (this might require a 486-class CPU) */
Wolfgang Denka1be4762008-05-20 16:00:29 +020030 movl %cr0, %eax
Ondrej Kupka19c114a2011-09-30 21:05:11 +110031 orl $(X86_CR0_NW | X86_CR0_CD), %eax
Wolfgang Denka1be4762008-05-20 16:00:29 +020032 movl %eax, %cr0
wdenk57b2d802003-06-27 21:31:46 +000033 wbinvd
34
Graeme Russ59da5a52010-04-24 00:05:43 +100035 /* load the temporary Global Descriptor Table */
Graeme Russ4fdcc422010-08-22 16:25:59 +100036o32 cs lidt idt_ptr
Wolfgang Denka1be4762008-05-20 16:00:29 +020037o32 cs lgdt gdt_ptr
wdenk591dda52002-11-18 00:14:45 +000038
wdenk591dda52002-11-18 00:14:45 +000039 /* Now, we enter protected mode */
Wolfgang Denka1be4762008-05-20 16:00:29 +020040 movl %cr0, %eax
Graeme Russ93efcb22011-02-12 15:11:32 +110041 orl $X86_CR0_PE, %eax
Wolfgang Denka1be4762008-05-20 16:00:29 +020042 movl %eax, %cr0
wdenk57b2d802003-06-27 21:31:46 +000043
wdenk591dda52002-11-18 00:14:45 +000044 /* Flush the prefetch queue */
Wolfgang Denka1be4762008-05-20 16:00:29 +020045 jmp ff
wdenk591dda52002-11-18 00:14:45 +000046ff:
Simon Glass1f4476c2014-11-06 13:20:10 -070047
Bin Meng65db0c92015-01-20 11:25:44 +080048 /* Finally restore BIST and jump to the 32-bit initialization code */
wdenk57b2d802003-06-27 21:31:46 +000049 movw $code32start, %ax
Graeme Russ3e6ec382010-10-07 20:03:21 +110050 movw %ax, %bp
Simon Glass1f4476c2014-11-06 13:20:10 -070051 movl %ecx, %eax
wdenk591dda52002-11-18 00:14:45 +000052o32 cs ljmp *(%bp)
53
54 /* 48-bit far pointer */
55code32start:
Wolfgang Denka1be4762008-05-20 16:00:29 +020056 .long _start /* offset */
57 .word 0x10 /* segment */
wdenk591dda52002-11-18 00:14:45 +000058
Graeme Russ4fdcc422010-08-22 16:25:59 +100059idt_ptr:
60 .word 0 /* limit */
61 .long 0 /* base */
62
Bin Meng65db0c92015-01-20 11:25:44 +080063 /*
64 * The following Global Descriptor Table is just enough to get us into
65 * 'Flat Protected Mode' - It will be discarded as soon as the final
66 * GDT is setup in a safe location in RAM
67 */
wdenk591dda52002-11-18 00:14:45 +000068gdt_ptr:
Bin Meng0f39bc02014-10-16 22:58:35 +080069 .word 0x1f /* limit (31 bytes = 4 GDT entries - 1) */
Bin Menga3c9fb02015-06-07 11:33:13 +080070 .long BOOT_SEG + gdt_rom /* base */
wdenk591dda52002-11-18 00:14:45 +000071
Bin Meng65db0c92015-01-20 11:25:44 +080072 /* Some CPUs are picky about GDT alignment... */
73 .align 16
Bin Menga3c9fb02015-06-07 11:33:13 +080074.globl gdt_rom
75gdt_rom:
Graeme Russaf3f2c82011-12-19 14:26:18 +110076 /*
77 * The GDT table ...
wdenk591dda52002-11-18 00:14:45 +000078 *
Wolfgang Denka1be4762008-05-20 16:00:29 +020079 * Selector Type
80 * 0x00 NULL
81 * 0x08 Unused
wdenk57b2d802003-06-27 21:31:46 +000082 * 0x10 32bit code
wdenk591dda52002-11-18 00:14:45 +000083 * 0x18 32bit data/stack
wdenk591dda52002-11-18 00:14:45 +000084 */
Graeme Russaf3f2c82011-12-19 14:26:18 +110085 /* The NULL Desciptor - Mandatory */
86 .word 0x0000 /* limit_low */
87 .word 0x0000 /* base_low */
88 .byte 0x00 /* base_middle */
89 .byte 0x00 /* access */
90 .byte 0x00 /* flags + limit_high */
91 .byte 0x00 /* base_high */
wdenk591dda52002-11-18 00:14:45 +000092
Graeme Russaf3f2c82011-12-19 14:26:18 +110093 /* Unused Desciptor - (matches Linux) */
94 .word 0x0000 /* limit_low */
95 .word 0x0000 /* base_low */
96 .byte 0x00 /* base_middle */
97 .byte 0x00 /* access */
98 .byte 0x00 /* flags + limit_high */
99 .byte 0x00 /* base_high */
wdenk591dda52002-11-18 00:14:45 +0000100
Graeme Russaf3f2c82011-12-19 14:26:18 +1100101 /*
102 * The Code Segment Descriptor:
103 * - Base = 0x00000000
104 * - Size = 4GB
105 * - Access = Present, Ring 0, Exec (Code), Readable
106 * - Flags = 4kB Granularity, 32-bit
107 */
108 .word 0xffff /* limit_low */
109 .word 0x0000 /* base_low */
110 .byte 0x00 /* base_middle */
111 .byte 0x9b /* access */
112 .byte 0xcf /* flags + limit_high */
113 .byte 0x00 /* base_high */
wdenk591dda52002-11-18 00:14:45 +0000114
Graeme Russaf3f2c82011-12-19 14:26:18 +1100115 /*
116 * The Data Segment Descriptor:
117 * - Base = 0x00000000
118 * - Size = 4GB
119 * - Access = Present, Ring 0, Non-Exec (Data), Writable
120 * - Flags = 4kB Granularity, 32-bit
121 */
122 .word 0xffff /* limit_low */
123 .word 0x0000 /* base_low */
124 .byte 0x00 /* base_middle */
125 .byte 0x93 /* access */
126 .byte 0xcf /* flags + limit_high */
127 .byte 0x00 /* base_high */