blob: 7dc53583662509b5a63704e7089f488709e3638d [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001/*
wdenk8bde7f72003-06-27 21:31:46 +00002 * U-boot - i386 Startup Code
wdenk2262cfe2002-11-18 00:14:45 +00003 *
wdenk7a8e9bed2003-05-31 18:35:21 +00004 * Copyright (c) 2002, 2003 Omicron Ceti AB, Daniel Engström <denaiel@omicron.se>
wdenk2262cfe2002-11-18 00:14:45 +00005 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
Graeme Russc81b26b2010-10-07 20:03:30 +110025#include <asm/global_data.h>
Graeme Russ0c24c9c2011-02-12 15:11:32 +110026#include <asm/processor-flags.h>
wdenk2262cfe2002-11-18 00:14:45 +000027
28#define BOOT_SEG 0xffff0000 /* linear segment of boot code */
29#define a32 .byte 0x67;
30#define o32 .byte 0x66;
31
32.section .start16, "ax"
33.code16
34.globl start16
wdenk8bde7f72003-06-27 21:31:46 +000035start16:
Graeme Russc81b26b2010-10-07 20:03:30 +110036 /* Set the Cold Boot / Hard Reset flag */
37 movl $GD_FLG_COLD_BOOT, %ebx
38
Graeme Russ8ffb2e82010-10-07 20:03:21 +110039 /*
40 * First we let the BSP do some early initialization
wdenk2262cfe2002-11-18 00:14:45 +000041 * this code have to map the flash to its final position
42 */
wdenk2262cfe2002-11-18 00:14:45 +000043 jmp board_init16
Graeme Russ88fa0a62010-10-07 20:03:27 +110044.globl board_init16_ret
wdenk8bde7f72003-06-27 21:31:46 +000045board_init16_ret:
46
wdenk2262cfe2002-11-18 00:14:45 +000047 /* Turn of cache (this might require a 486-class CPU) */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020048 movl %cr0, %eax
Graeme Russ0c24c9c2011-02-12 15:11:32 +110049 orl $(X86_CR0_NW & X86_CR0_CD), %eax
Wolfgang Denk53677ef2008-05-20 16:00:29 +020050 movl %eax, %cr0
wdenk8bde7f72003-06-27 21:31:46 +000051 wbinvd
52
Graeme Russc14a3662010-04-24 00:05:43 +100053 /* load the temporary Global Descriptor Table */
Graeme Russ797960f2010-08-22 16:25:59 +100054o32 cs lidt idt_ptr
Wolfgang Denk53677ef2008-05-20 16:00:29 +020055o32 cs lgdt gdt_ptr
wdenk2262cfe2002-11-18 00:14:45 +000056
wdenk2262cfe2002-11-18 00:14:45 +000057 /* Now, we enter protected mode */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020058 movl %cr0, %eax
Graeme Russ0c24c9c2011-02-12 15:11:32 +110059 orl $X86_CR0_PE, %eax
Wolfgang Denk53677ef2008-05-20 16:00:29 +020060 movl %eax, %cr0
wdenk8bde7f72003-06-27 21:31:46 +000061
wdenk2262cfe2002-11-18 00:14:45 +000062 /* Flush the prefetch queue */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020063 jmp ff
wdenk2262cfe2002-11-18 00:14:45 +000064ff:
wdenk2262cfe2002-11-18 00:14:45 +000065 /* Finally jump to the 32bit initialization code */
wdenk8bde7f72003-06-27 21:31:46 +000066 movw $code32start, %ax
Graeme Russ8ffb2e82010-10-07 20:03:21 +110067 movw %ax, %bp
wdenk2262cfe2002-11-18 00:14:45 +000068o32 cs ljmp *(%bp)
69
70 /* 48-bit far pointer */
71code32start:
Wolfgang Denk53677ef2008-05-20 16:00:29 +020072 .long _start /* offset */
73 .word 0x10 /* segment */
wdenk2262cfe2002-11-18 00:14:45 +000074
Graeme Russ797960f2010-08-22 16:25:59 +100075idt_ptr:
76 .word 0 /* limit */
77 .long 0 /* base */
78
Graeme Russc14a3662010-04-24 00:05:43 +100079/*
80 * The following Global Descriptor Table is just enough to get us into
81 * 'Flat Protected Mode' - It will be discarded as soon as the final
82 * GDT is setup in a safe location in RAM
83 */
wdenk2262cfe2002-11-18 00:14:45 +000084gdt_ptr:
Graeme Russc14a3662010-04-24 00:05:43 +100085 .word 0x20 /* limit (32 bytes = 4 GDT entries) */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020086 .long BOOT_SEG + gdt /* base */
wdenk2262cfe2002-11-18 00:14:45 +000087
wdenk8bde7f72003-06-27 21:31:46 +000088 /* The GDT table ...
wdenk2262cfe2002-11-18 00:14:45 +000089 *
Wolfgang Denk53677ef2008-05-20 16:00:29 +020090 * Selector Type
91 * 0x00 NULL
92 * 0x08 Unused
wdenk8bde7f72003-06-27 21:31:46 +000093 * 0x10 32bit code
wdenk2262cfe2002-11-18 00:14:45 +000094 * 0x18 32bit data/stack
wdenk2262cfe2002-11-18 00:14:45 +000095 */
96
97gdt:
Wolfgang Denk53677ef2008-05-20 16:00:29 +020098 .word 0, 0, 0, 0 /* NULL */
99 .word 0, 0, 0, 0 /* unused */
wdenk2262cfe2002-11-18 00:14:45 +0000100
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200101 .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
102 .word 0 /* base address = 0 */
103 .word 0x9B00 /* code read/exec */
104 .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */
wdenk2262cfe2002-11-18 00:14:45 +0000105
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200106 .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
107 .word 0x0 /* base address = 0 */
108 .word 0x9300 /* data read/write */
109 .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */