blob: e718d4b26ff5fd79a9a08a0bfba38c426e373bb6 [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001/*
Graeme Russfea25722011-04-13 19:43:28 +10002 * U-boot - x86 Startup Code
wdenk2262cfe2002-11-18 00:14:45 +00003 *
Graeme Russdbf71152011-04-13 19:43:26 +10004 * (C) Copyright 2008-2011
5 * Graeme Russ, <graeme.russ@gmail.com>
6 *
7 * (C) Copyright 2002,2003
Albert ARIBAUDfa82f872011-08-04 18:45:45 +02008 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenk2262cfe2002-11-18 00:14:45 +00009 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
wdenk2262cfe2002-11-18 00:14:45 +000011 */
12
Graeme Russc81b26b2010-10-07 20:03:30 +110013#include <asm/global_data.h>
Graeme Russ0c24c9c2011-02-12 15:11:32 +110014#include <asm/processor-flags.h>
wdenk2262cfe2002-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
wdenk8bde7f72003-06-27 21:31:46 +000023start16:
Gabe Black91d82a22012-11-03 11:41:28 +000024 /* Set the Cold Boot / Hard Reset flag */
25 movl $GD_FLG_COLD_BOOT, %ebx
26
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
wdenk8bde7f72003-06-27 21:31:46 +000031 wbinvd
32
Graeme Russc14a3662010-04-24 00:05:43 +100033 /* load the temporary Global Descriptor Table */
Graeme Russ797960f2010-08-22 16:25:59 +100034o32 cs lidt idt_ptr
Wolfgang Denk53677ef2008-05-20 16:00:29 +020035o32 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:
wdenk2262cfe2002-11-18 00:14:45 +000045 /* Finally jump to the 32bit initialization code */
wdenk8bde7f72003-06-27 21:31:46 +000046 movw $code32start, %ax
Graeme Russ8ffb2e82010-10-07 20:03:21 +110047 movw %ax, %bp
wdenk2262cfe2002-11-18 00:14:45 +000048o32 cs ljmp *(%bp)
49
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
Graeme Russc14a3662010-04-24 00:05:43 +100059/*
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) */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020066 .long BOOT_SEG + gdt /* base */
wdenk2262cfe2002-11-18 00:14:45 +000067
Graeme Russ58c7a672011-12-19 14:26:18 +110068/* Some CPUs are picky about GDT alignment... */
69.align 16
70gdt:
71 /*
72 * The GDT table ...
wdenk2262cfe2002-11-18 00:14:45 +000073 *
Wolfgang Denk53677ef2008-05-20 16:00:29 +020074 * Selector Type
75 * 0x00 NULL
76 * 0x08 Unused
wdenk8bde7f72003-06-27 21:31:46 +000077 * 0x10 32bit code
wdenk2262cfe2002-11-18 00:14:45 +000078 * 0x18 32bit data/stack
wdenk2262cfe2002-11-18 00:14:45 +000079 */
Graeme Russ58c7a672011-12-19 14:26:18 +110080 /* The NULL Desciptor - Mandatory */
81 .word 0x0000 /* limit_low */
82 .word 0x0000 /* base_low */
83 .byte 0x00 /* base_middle */
84 .byte 0x00 /* access */
85 .byte 0x00 /* flags + limit_high */
86 .byte 0x00 /* base_high */
wdenk2262cfe2002-11-18 00:14:45 +000087
Graeme Russ58c7a672011-12-19 14:26:18 +110088 /* Unused Desciptor - (matches Linux) */
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 /*
97 * The Code Segment Descriptor:
98 * - Base = 0x00000000
99 * - Size = 4GB
100 * - Access = Present, Ring 0, Exec (Code), Readable
101 * - Flags = 4kB Granularity, 32-bit
102 */
103 .word 0xffff /* limit_low */
104 .word 0x0000 /* base_low */
105 .byte 0x00 /* base_middle */
106 .byte 0x9b /* access */
107 .byte 0xcf /* flags + limit_high */
108 .byte 0x00 /* base_high */
wdenk2262cfe2002-11-18 00:14:45 +0000109
Graeme Russ58c7a672011-12-19 14:26:18 +1100110 /*
111 * The Data Segment Descriptor:
112 * - Base = 0x00000000
113 * - Size = 4GB
114 * - Access = Present, Ring 0, Non-Exec (Data), Writable
115 * - Flags = 4kB Granularity, 32-bit
116 */
117 .word 0xffff /* limit_low */
118 .word 0x0000 /* base_low */
119 .byte 0x00 /* base_middle */
120 .byte 0x93 /* access */
121 .byte 0xcf /* flags + limit_high */
122 .byte 0x00 /* base_high */