blob: 33e53cdb3b660d908c2b6bfa7e44929b3b5e5eac [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 *
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 Russc81b26b2010-10-07 20:03:30 +110029#include <asm/global_data.h>
Graeme Russ0c24c9c2011-02-12 15:11:32 +110030#include <asm/processor-flags.h>
wdenk2262cfe2002-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
wdenk8bde7f72003-06-27 21:31:46 +000039start16:
Graeme Russ8ffb2e82010-10-07 20:03:21 +110040 /*
41 * First we let the BSP do some early initialization
wdenk2262cfe2002-11-18 00:14:45 +000042 * this code have to map the flash to its final position
43 */
wdenk2262cfe2002-11-18 00:14:45 +000044 jmp board_init16
Graeme Russ88fa0a62010-10-07 20:03:27 +110045.globl board_init16_ret
wdenk8bde7f72003-06-27 21:31:46 +000046board_init16_ret:
47
wdenk2262cfe2002-11-18 00:14:45 +000048 /* Turn of cache (this might require a 486-class CPU) */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020049 movl %cr0, %eax
Ondrej Kupka7b3d5382011-09-30 21:05:11 +110050 orl $(X86_CR0_NW | X86_CR0_CD), %eax
Wolfgang Denk53677ef2008-05-20 16:00:29 +020051 movl %eax, %cr0
wdenk8bde7f72003-06-27 21:31:46 +000052 wbinvd
53
Graeme Russc14a3662010-04-24 00:05:43 +100054 /* load the temporary Global Descriptor Table */
Graeme Russ797960f2010-08-22 16:25:59 +100055o32 cs lidt idt_ptr
Wolfgang Denk53677ef2008-05-20 16:00:29 +020056o32 cs lgdt gdt_ptr
wdenk2262cfe2002-11-18 00:14:45 +000057
wdenk2262cfe2002-11-18 00:14:45 +000058 /* Now, we enter protected mode */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020059 movl %cr0, %eax
Graeme Russ0c24c9c2011-02-12 15:11:32 +110060 orl $X86_CR0_PE, %eax
Wolfgang Denk53677ef2008-05-20 16:00:29 +020061 movl %eax, %cr0
wdenk8bde7f72003-06-27 21:31:46 +000062
wdenk2262cfe2002-11-18 00:14:45 +000063 /* Flush the prefetch queue */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020064 jmp ff
wdenk2262cfe2002-11-18 00:14:45 +000065ff:
wdenk2262cfe2002-11-18 00:14:45 +000066 /* Finally jump to the 32bit initialization code */
wdenk8bde7f72003-06-27 21:31:46 +000067 movw $code32start, %ax
Graeme Russ8ffb2e82010-10-07 20:03:21 +110068 movw %ax, %bp
wdenk2262cfe2002-11-18 00:14:45 +000069o32 cs ljmp *(%bp)
70
71 /* 48-bit far pointer */
72code32start:
Wolfgang Denk53677ef2008-05-20 16:00:29 +020073 .long _start /* offset */
74 .word 0x10 /* segment */
wdenk2262cfe2002-11-18 00:14:45 +000075
Graeme Russ797960f2010-08-22 16:25:59 +100076idt_ptr:
77 .word 0 /* limit */
78 .long 0 /* base */
79
Graeme Russc14a3662010-04-24 00:05:43 +100080/*
81 * The following Global Descriptor Table is just enough to get us into
82 * 'Flat Protected Mode' - It will be discarded as soon as the final
83 * GDT is setup in a safe location in RAM
84 */
wdenk2262cfe2002-11-18 00:14:45 +000085gdt_ptr:
Graeme Russc14a3662010-04-24 00:05:43 +100086 .word 0x20 /* limit (32 bytes = 4 GDT entries) */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020087 .long BOOT_SEG + gdt /* base */
wdenk2262cfe2002-11-18 00:14:45 +000088
wdenk8bde7f72003-06-27 21:31:46 +000089 /* The GDT table ...
wdenk2262cfe2002-11-18 00:14:45 +000090 *
Wolfgang Denk53677ef2008-05-20 16:00:29 +020091 * Selector Type
92 * 0x00 NULL
93 * 0x08 Unused
wdenk8bde7f72003-06-27 21:31:46 +000094 * 0x10 32bit code
wdenk2262cfe2002-11-18 00:14:45 +000095 * 0x18 32bit data/stack
wdenk2262cfe2002-11-18 00:14:45 +000096 */
97
98gdt:
Wolfgang Denk53677ef2008-05-20 16:00:29 +020099 .word 0, 0, 0, 0 /* NULL */
100 .word 0, 0, 0, 0 /* unused */
wdenk2262cfe2002-11-18 00:14:45 +0000101
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200102 .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
103 .word 0 /* base address = 0 */
104 .word 0x9B00 /* code read/exec */
105 .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */
wdenk2262cfe2002-11-18 00:14:45 +0000106
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200107 .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
108 .word 0x0 /* base address = 0 */
109 .word 0x9300 /* data read/write */
110 .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */