2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2002-11-18 00:14:45 +00:00
|
|
|
/*
|
2015-01-20 03:25:44 +00:00
|
|
|
* U-Boot - x86 Startup Code
|
2002-11-18 00:14:45 +00:00
|
|
|
*
|
2011-04-13 09:43:26 +00:00
|
|
|
* (C) Copyright 2008-2011
|
|
|
|
* Graeme Russ, <graeme.russ@gmail.com>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002,2003
|
2011-08-04 16:45:45 +00:00
|
|
|
* Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
|
2002-11-18 00:14:45 +00:00
|
|
|
*/
|
|
|
|
|
2010-10-07 09:03:30 +00:00
|
|
|
#include <asm/global_data.h>
|
2011-02-12 04:11:32 +00:00
|
|
|
#include <asm/processor-flags.h>
|
2002-11-18 00:14:45 +00:00
|
|
|
|
|
|
|
#define BOOT_SEG 0xffff0000 /* linear segment of boot code */
|
|
|
|
#define a32 .byte 0x67;
|
|
|
|
#define o32 .byte 0x66;
|
|
|
|
|
|
|
|
.section .start16, "ax"
|
|
|
|
.code16
|
|
|
|
.globl start16
|
2003-06-27 21:31:46 +00:00
|
|
|
start16:
|
2014-11-06 20:20:10 +00:00
|
|
|
/* Save BIST */
|
|
|
|
movl %eax, %ecx
|
|
|
|
|
2012-11-03 11:41:28 +00:00
|
|
|
/* Set the Cold Boot / Hard Reset flag */
|
|
|
|
movl $GD_FLG_COLD_BOOT, %ebx
|
|
|
|
|
2014-11-06 20:20:03 +00:00
|
|
|
xorl %eax, %eax
|
2015-01-20 03:25:44 +00:00
|
|
|
movl %eax, %cr3 /* Invalidate TLB */
|
2014-11-06 20:20:03 +00:00
|
|
|
|
2014-11-06 20:20:01 +00:00
|
|
|
/* Turn off cache (this might require a 486-class CPU) */
|
2008-05-20 14:00:29 +00:00
|
|
|
movl %cr0, %eax
|
2011-09-30 10:05:11 +00:00
|
|
|
orl $(X86_CR0_NW | X86_CR0_CD), %eax
|
2008-05-20 14:00:29 +00:00
|
|
|
movl %eax, %cr0
|
2003-06-27 21:31:46 +00:00
|
|
|
wbinvd
|
|
|
|
|
2010-04-23 14:05:43 +00:00
|
|
|
/* load the temporary Global Descriptor Table */
|
2010-08-22 06:25:59 +00:00
|
|
|
o32 cs lidt idt_ptr
|
2008-05-20 14:00:29 +00:00
|
|
|
o32 cs lgdt gdt_ptr
|
2002-11-18 00:14:45 +00:00
|
|
|
|
|
|
|
/* Now, we enter protected mode */
|
2008-05-20 14:00:29 +00:00
|
|
|
movl %cr0, %eax
|
2011-02-12 04:11:32 +00:00
|
|
|
orl $X86_CR0_PE, %eax
|
2008-05-20 14:00:29 +00:00
|
|
|
movl %eax, %cr0
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
/* Flush the prefetch queue */
|
2008-05-20 14:00:29 +00:00
|
|
|
jmp ff
|
2002-11-18 00:14:45 +00:00
|
|
|
ff:
|
2014-11-06 20:20:10 +00:00
|
|
|
|
2015-01-20 03:25:44 +00:00
|
|
|
/* Finally restore BIST and jump to the 32-bit initialization code */
|
2003-06-27 21:31:46 +00:00
|
|
|
movw $code32start, %ax
|
2010-10-07 09:03:21 +00:00
|
|
|
movw %ax, %bp
|
2014-11-06 20:20:10 +00:00
|
|
|
movl %ecx, %eax
|
2002-11-18 00:14:45 +00:00
|
|
|
o32 cs ljmp *(%bp)
|
|
|
|
|
|
|
|
/* 48-bit far pointer */
|
|
|
|
code32start:
|
2008-05-20 14:00:29 +00:00
|
|
|
.long _start /* offset */
|
|
|
|
.word 0x10 /* segment */
|
2002-11-18 00:14:45 +00:00
|
|
|
|
2010-08-22 06:25:59 +00:00
|
|
|
idt_ptr:
|
|
|
|
.word 0 /* limit */
|
|
|
|
.long 0 /* base */
|
|
|
|
|
2015-01-20 03:25:44 +00:00
|
|
|
/*
|
|
|
|
* The following Global Descriptor Table is just enough to get us into
|
|
|
|
* 'Flat Protected Mode' - It will be discarded as soon as the final
|
|
|
|
* GDT is setup in a safe location in RAM
|
|
|
|
*/
|
2002-11-18 00:14:45 +00:00
|
|
|
gdt_ptr:
|
2014-10-16 14:58:35 +00:00
|
|
|
.word 0x1f /* limit (31 bytes = 4 GDT entries - 1) */
|
2015-06-07 03:33:13 +00:00
|
|
|
.long BOOT_SEG + gdt_rom /* base */
|
2002-11-18 00:14:45 +00:00
|
|
|
|
2015-01-20 03:25:44 +00:00
|
|
|
/* Some CPUs are picky about GDT alignment... */
|
|
|
|
.align 16
|
2015-06-07 03:33:13 +00:00
|
|
|
.globl gdt_rom
|
|
|
|
gdt_rom:
|
2011-12-19 03:26:18 +00:00
|
|
|
/*
|
|
|
|
* The GDT table ...
|
2002-11-18 00:14:45 +00:00
|
|
|
*
|
2008-05-20 14:00:29 +00:00
|
|
|
* Selector Type
|
|
|
|
* 0x00 NULL
|
|
|
|
* 0x08 Unused
|
2003-06-27 21:31:46 +00:00
|
|
|
* 0x10 32bit code
|
2002-11-18 00:14:45 +00:00
|
|
|
* 0x18 32bit data/stack
|
|
|
|
*/
|
2011-12-19 03:26:18 +00:00
|
|
|
/* The NULL Desciptor - Mandatory */
|
|
|
|
.word 0x0000 /* limit_low */
|
|
|
|
.word 0x0000 /* base_low */
|
|
|
|
.byte 0x00 /* base_middle */
|
|
|
|
.byte 0x00 /* access */
|
|
|
|
.byte 0x00 /* flags + limit_high */
|
|
|
|
.byte 0x00 /* base_high */
|
2002-11-18 00:14:45 +00:00
|
|
|
|
2011-12-19 03:26:18 +00:00
|
|
|
/* Unused Desciptor - (matches Linux) */
|
|
|
|
.word 0x0000 /* limit_low */
|
|
|
|
.word 0x0000 /* base_low */
|
|
|
|
.byte 0x00 /* base_middle */
|
|
|
|
.byte 0x00 /* access */
|
|
|
|
.byte 0x00 /* flags + limit_high */
|
|
|
|
.byte 0x00 /* base_high */
|
2008-05-20 14:00:29 +00:00
|
|
|
|
2011-12-19 03:26:18 +00:00
|
|
|
/*
|
|
|
|
* The Code Segment Descriptor:
|
|
|
|
* - Base = 0x00000000
|
|
|
|
* - Size = 4GB
|
|
|
|
* - Access = Present, Ring 0, Exec (Code), Readable
|
|
|
|
* - Flags = 4kB Granularity, 32-bit
|
|
|
|
*/
|
|
|
|
.word 0xffff /* limit_low */
|
|
|
|
.word 0x0000 /* base_low */
|
|
|
|
.byte 0x00 /* base_middle */
|
|
|
|
.byte 0x9b /* access */
|
|
|
|
.byte 0xcf /* flags + limit_high */
|
|
|
|
.byte 0x00 /* base_high */
|
2008-05-20 14:00:29 +00:00
|
|
|
|
2011-12-19 03:26:18 +00:00
|
|
|
/*
|
|
|
|
* The Data Segment Descriptor:
|
|
|
|
* - Base = 0x00000000
|
|
|
|
* - Size = 4GB
|
|
|
|
* - Access = Present, Ring 0, Non-Exec (Data), Writable
|
|
|
|
* - Flags = 4kB Granularity, 32-bit
|
|
|
|
*/
|
|
|
|
.word 0xffff /* limit_low */
|
|
|
|
.word 0x0000 /* base_low */
|
|
|
|
.byte 0x00 /* base_middle */
|
|
|
|
.byte 0x93 /* access */
|
|
|
|
.byte 0xcf /* flags + limit_high */
|
|
|
|
.byte 0x00 /* base_high */
|