blob: f1b9d0a0c9719f0c9946bc4243c43802a529323d [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
8 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenk591dda52002-11-18 00:14:45 +00009 *
10 * See file CREDITS for list of people who contributed to this
11 * project.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * MA 02111-1307 USA
27 */
28
Graeme Russ80ccbac2010-10-07 20:03:30 +110029#include <asm/global_data.h>
Graeme Russ93efcb22011-02-12 15:11:32 +110030#include <asm/processor-flags.h>
wdenk591dda52002-11-18 00:14:45 +000031
32#define BOOT_SEG 0xffff0000 /* linear segment of boot code */
33#define a32 .byte 0x67;
34#define o32 .byte 0x66;
35
36.section .start16, "ax"
37.code16
38.globl start16
wdenk57b2d802003-06-27 21:31:46 +000039start16:
Graeme Russ80ccbac2010-10-07 20:03:30 +110040 /* Set the Cold Boot / Hard Reset flag */
41 movl $GD_FLG_COLD_BOOT, %ebx
42
Graeme Russ3e6ec382010-10-07 20:03:21 +110043 /*
44 * First we let the BSP do some early initialization
wdenk591dda52002-11-18 00:14:45 +000045 * this code have to map the flash to its final position
46 */
wdenk591dda52002-11-18 00:14:45 +000047 jmp board_init16
Graeme Russ157b0e92010-10-07 20:03:27 +110048.globl board_init16_ret
wdenk57b2d802003-06-27 21:31:46 +000049board_init16_ret:
50
wdenk591dda52002-11-18 00:14:45 +000051 /* Turn of cache (this might require a 486-class CPU) */
Wolfgang Denka1be4762008-05-20 16:00:29 +020052 movl %cr0, %eax
Graeme Russ93efcb22011-02-12 15:11:32 +110053 orl $(X86_CR0_NW & X86_CR0_CD), %eax
Wolfgang Denka1be4762008-05-20 16:00:29 +020054 movl %eax, %cr0
wdenk57b2d802003-06-27 21:31:46 +000055 wbinvd
56
Graeme Russ59da5a52010-04-24 00:05:43 +100057 /* load the temporary Global Descriptor Table */
Graeme Russ4fdcc422010-08-22 16:25:59 +100058o32 cs lidt idt_ptr
Wolfgang Denka1be4762008-05-20 16:00:29 +020059o32 cs lgdt gdt_ptr
wdenk591dda52002-11-18 00:14:45 +000060
wdenk591dda52002-11-18 00:14:45 +000061 /* Now, we enter protected mode */
Wolfgang Denka1be4762008-05-20 16:00:29 +020062 movl %cr0, %eax
Graeme Russ93efcb22011-02-12 15:11:32 +110063 orl $X86_CR0_PE, %eax
Wolfgang Denka1be4762008-05-20 16:00:29 +020064 movl %eax, %cr0
wdenk57b2d802003-06-27 21:31:46 +000065
wdenk591dda52002-11-18 00:14:45 +000066 /* Flush the prefetch queue */
Wolfgang Denka1be4762008-05-20 16:00:29 +020067 jmp ff
wdenk591dda52002-11-18 00:14:45 +000068ff:
wdenk591dda52002-11-18 00:14:45 +000069 /* Finally jump to the 32bit initialization code */
wdenk57b2d802003-06-27 21:31:46 +000070 movw $code32start, %ax
Graeme Russ3e6ec382010-10-07 20:03:21 +110071 movw %ax, %bp
wdenk591dda52002-11-18 00:14:45 +000072o32 cs ljmp *(%bp)
73
74 /* 48-bit far pointer */
75code32start:
Wolfgang Denka1be4762008-05-20 16:00:29 +020076 .long _start /* offset */
77 .word 0x10 /* segment */
wdenk591dda52002-11-18 00:14:45 +000078
Graeme Russ4fdcc422010-08-22 16:25:59 +100079idt_ptr:
80 .word 0 /* limit */
81 .long 0 /* base */
82
Graeme Russ59da5a52010-04-24 00:05:43 +100083/*
84 * The following Global Descriptor Table is just enough to get us into
85 * 'Flat Protected Mode' - It will be discarded as soon as the final
86 * GDT is setup in a safe location in RAM
87 */
wdenk591dda52002-11-18 00:14:45 +000088gdt_ptr:
Graeme Russ59da5a52010-04-24 00:05:43 +100089 .word 0x20 /* limit (32 bytes = 4 GDT entries) */
Wolfgang Denka1be4762008-05-20 16:00:29 +020090 .long BOOT_SEG + gdt /* base */
wdenk591dda52002-11-18 00:14:45 +000091
wdenk57b2d802003-06-27 21:31:46 +000092 /* The GDT table ...
wdenk591dda52002-11-18 00:14:45 +000093 *
Wolfgang Denka1be4762008-05-20 16:00:29 +020094 * Selector Type
95 * 0x00 NULL
96 * 0x08 Unused
wdenk57b2d802003-06-27 21:31:46 +000097 * 0x10 32bit code
wdenk591dda52002-11-18 00:14:45 +000098 * 0x18 32bit data/stack
wdenk591dda52002-11-18 00:14:45 +000099 */
100
101gdt:
Wolfgang Denka1be4762008-05-20 16:00:29 +0200102 .word 0, 0, 0, 0 /* NULL */
103 .word 0, 0, 0, 0 /* unused */
wdenk591dda52002-11-18 00:14:45 +0000104
Wolfgang Denka1be4762008-05-20 16:00:29 +0200105 .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
106 .word 0 /* base address = 0 */
107 .word 0x9B00 /* code read/exec */
108 .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */
wdenk591dda52002-11-18 00:14:45 +0000109
Wolfgang Denka1be4762008-05-20 16:00:29 +0200110 .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
111 .word 0x0 /* base address = 0 */
112 .word 0x9300 /* data read/write */
113 .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */