2002-11-18 00:14:45 +00:00
|
|
|
/*
|
2011-04-13 09:43:28 +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
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
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:
|
2012-11-03 11:41:28 +00:00
|
|
|
/* Set the Cold Boot / Hard Reset flag */
|
|
|
|
movl $GD_FLG_COLD_BOOT, %ebx
|
|
|
|
|
2010-10-07 09:03:21 +00:00
|
|
|
/*
|
|
|
|
* First we let the BSP do some early initialization
|
2002-11-18 00:14:45 +00:00
|
|
|
* this code have to map the flash to its final position
|
|
|
|
*/
|
|
|
|
jmp board_init16
|
2010-10-07 09:03:27 +00:00
|
|
|
.globl board_init16_ret
|
2003-06-27 21:31:46 +00:00
|
|
|
board_init16_ret:
|
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
/* Turn of 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:
|
|
|
|
/* Finally jump to the 32bit initialization code */
|
2003-06-27 21:31:46 +00:00
|
|
|
movw $code32start, %ax
|
2010-10-07 09:03:21 +00:00
|
|
|
movw %ax, %bp
|
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 */
|
|
|
|
|
2010-04-23 14:05:43 +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:
|
2010-04-23 14:05:43 +00:00
|
|
|
.word 0x20 /* limit (32 bytes = 4 GDT entries) */
|
2008-05-20 14:00:29 +00:00
|
|
|
.long BOOT_SEG + gdt /* base */
|
2002-11-18 00:14:45 +00:00
|
|
|
|
2011-12-19 03:26:18 +00:00
|
|
|
/* Some CPUs are picky about GDT alignment... */
|
|
|
|
.align 16
|
|
|
|
gdt:
|
|
|
|
/*
|
|
|
|
* 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 */
|