blob: 8b9b327cd48734fbd50b71dbe3d6a238151d7074 [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001/*
Graeme Russcbfce1d2011-04-13 19:43:28 +10002 * 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:
Gabe Blackef899322012-11-03 11:41:28 +000024 /* Set the Cold Boot / Hard Reset flag */
25 movl $GD_FLG_COLD_BOOT, %ebx
26
Graeme Russ3e6ec382010-10-07 20:03:21 +110027 /*
28 * First we let the BSP do some early initialization
wdenk591dda52002-11-18 00:14:45 +000029 * this code have to map the flash to its final position
30 */
wdenk591dda52002-11-18 00:14:45 +000031 jmp board_init16
Graeme Russ157b0e92010-10-07 20:03:27 +110032.globl board_init16_ret
wdenk57b2d802003-06-27 21:31:46 +000033board_init16_ret:
34
wdenk591dda52002-11-18 00:14:45 +000035 /* Turn of cache (this might require a 486-class CPU) */
Wolfgang Denka1be4762008-05-20 16:00:29 +020036 movl %cr0, %eax
Ondrej Kupka19c114a2011-09-30 21:05:11 +110037 orl $(X86_CR0_NW | X86_CR0_CD), %eax
Wolfgang Denka1be4762008-05-20 16:00:29 +020038 movl %eax, %cr0
wdenk57b2d802003-06-27 21:31:46 +000039 wbinvd
40
Graeme Russ59da5a52010-04-24 00:05:43 +100041 /* load the temporary Global Descriptor Table */
Graeme Russ4fdcc422010-08-22 16:25:59 +100042o32 cs lidt idt_ptr
Wolfgang Denka1be4762008-05-20 16:00:29 +020043o32 cs lgdt gdt_ptr
wdenk591dda52002-11-18 00:14:45 +000044
wdenk591dda52002-11-18 00:14:45 +000045 /* Now, we enter protected mode */
Wolfgang Denka1be4762008-05-20 16:00:29 +020046 movl %cr0, %eax
Graeme Russ93efcb22011-02-12 15:11:32 +110047 orl $X86_CR0_PE, %eax
Wolfgang Denka1be4762008-05-20 16:00:29 +020048 movl %eax, %cr0
wdenk57b2d802003-06-27 21:31:46 +000049
wdenk591dda52002-11-18 00:14:45 +000050 /* Flush the prefetch queue */
Wolfgang Denka1be4762008-05-20 16:00:29 +020051 jmp ff
wdenk591dda52002-11-18 00:14:45 +000052ff:
wdenk591dda52002-11-18 00:14:45 +000053 /* Finally jump to the 32bit initialization code */
wdenk57b2d802003-06-27 21:31:46 +000054 movw $code32start, %ax
Graeme Russ3e6ec382010-10-07 20:03:21 +110055 movw %ax, %bp
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
Graeme Russ59da5a52010-04-24 00:05:43 +100067/*
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:
Graeme Russ59da5a52010-04-24 00:05:43 +100073 .word 0x20 /* limit (32 bytes = 4 GDT entries) */
Wolfgang Denka1be4762008-05-20 16:00:29 +020074 .long BOOT_SEG + gdt /* base */
wdenk591dda52002-11-18 00:14:45 +000075
Graeme Russaf3f2c82011-12-19 14:26:18 +110076/* Some CPUs are picky about GDT alignment... */
77.align 16
78gdt:
79 /*
80 * The GDT table ...
wdenk591dda52002-11-18 00:14:45 +000081 *
Wolfgang Denka1be4762008-05-20 16:00:29 +020082 * Selector Type
83 * 0x00 NULL
84 * 0x08 Unused
wdenk57b2d802003-06-27 21:31:46 +000085 * 0x10 32bit code
wdenk591dda52002-11-18 00:14:45 +000086 * 0x18 32bit data/stack
wdenk591dda52002-11-18 00:14:45 +000087 */
Graeme Russaf3f2c82011-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 */
wdenk591dda52002-11-18 00:14:45 +000095
Graeme Russaf3f2c82011-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 */
wdenk591dda52002-11-18 00:14:45 +0000103
Graeme Russaf3f2c82011-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 */
wdenk591dda52002-11-18 00:14:45 +0000117
Graeme Russaf3f2c82011-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 */