blob: 0a5823d3c29ff32c071daf006bc099c972e44293 [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001/*
wdenk57b2d802003-06-27 21:31:46 +00002 * U-boot - i386 Startup Code
wdenk591dda52002-11-18 00:14:45 +00003 *
wdenkabda5ca2003-05-31 18:35:21 +00004 * Copyright (c) 2002, 2003 Omicron Ceti AB, Daniel Engström <denaiel@omicron.se>
wdenk591dda52002-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 Russ80ccbac2010-10-07 20:03:30 +110025#include <asm/global_data.h>
wdenk591dda52002-11-18 00:14:45 +000026
27#define BOOT_SEG 0xffff0000 /* linear segment of boot code */
28#define a32 .byte 0x67;
29#define o32 .byte 0x66;
30
31.section .start16, "ax"
32.code16
33.globl start16
wdenk57b2d802003-06-27 21:31:46 +000034start16:
Graeme Russ80ccbac2010-10-07 20:03:30 +110035 /* Set the Cold Boot / Hard Reset flag */
36 movl $GD_FLG_COLD_BOOT, %ebx
37
Graeme Russ3e6ec382010-10-07 20:03:21 +110038 /*
39 * First we let the BSP do some early initialization
wdenk591dda52002-11-18 00:14:45 +000040 * this code have to map the flash to its final position
41 */
wdenk591dda52002-11-18 00:14:45 +000042 jmp board_init16
Graeme Russ157b0e92010-10-07 20:03:27 +110043.globl board_init16_ret
wdenk57b2d802003-06-27 21:31:46 +000044board_init16_ret:
45
wdenk591dda52002-11-18 00:14:45 +000046 /* Turn of cache (this might require a 486-class CPU) */
Wolfgang Denka1be4762008-05-20 16:00:29 +020047 movl %cr0, %eax
Graeme Russ3e6ec382010-10-07 20:03:21 +110048 orl $0x60000000, %eax
Wolfgang Denka1be4762008-05-20 16:00:29 +020049 movl %eax, %cr0
wdenk57b2d802003-06-27 21:31:46 +000050 wbinvd
51
Graeme Russ59da5a52010-04-24 00:05:43 +100052 /* load the temporary Global Descriptor Table */
Graeme Russ4fdcc422010-08-22 16:25:59 +100053o32 cs lidt idt_ptr
Wolfgang Denka1be4762008-05-20 16:00:29 +020054o32 cs lgdt gdt_ptr
wdenk591dda52002-11-18 00:14:45 +000055
wdenk591dda52002-11-18 00:14:45 +000056 /* Now, we enter protected mode */
Wolfgang Denka1be4762008-05-20 16:00:29 +020057 movl %cr0, %eax
Graeme Russ3e6ec382010-10-07 20:03:21 +110058 orl $1, %eax
Wolfgang Denka1be4762008-05-20 16:00:29 +020059 movl %eax, %cr0
wdenk57b2d802003-06-27 21:31:46 +000060
wdenk591dda52002-11-18 00:14:45 +000061 /* Flush the prefetch queue */
Wolfgang Denka1be4762008-05-20 16:00:29 +020062 jmp ff
wdenk591dda52002-11-18 00:14:45 +000063ff:
wdenk591dda52002-11-18 00:14:45 +000064 /* Finally jump to the 32bit initialization code */
wdenk57b2d802003-06-27 21:31:46 +000065 movw $code32start, %ax
Graeme Russ3e6ec382010-10-07 20:03:21 +110066 movw %ax, %bp
wdenk591dda52002-11-18 00:14:45 +000067o32 cs ljmp *(%bp)
68
69 /* 48-bit far pointer */
70code32start:
Wolfgang Denka1be4762008-05-20 16:00:29 +020071 .long _start /* offset */
72 .word 0x10 /* segment */
wdenk591dda52002-11-18 00:14:45 +000073
Graeme Russ4fdcc422010-08-22 16:25:59 +100074idt_ptr:
75 .word 0 /* limit */
76 .long 0 /* base */
77
Graeme Russ59da5a52010-04-24 00:05:43 +100078/*
79 * The following Global Descriptor Table is just enough to get us into
80 * 'Flat Protected Mode' - It will be discarded as soon as the final
81 * GDT is setup in a safe location in RAM
82 */
wdenk591dda52002-11-18 00:14:45 +000083gdt_ptr:
Graeme Russ59da5a52010-04-24 00:05:43 +100084 .word 0x20 /* limit (32 bytes = 4 GDT entries) */
Wolfgang Denka1be4762008-05-20 16:00:29 +020085 .long BOOT_SEG + gdt /* base */
wdenk591dda52002-11-18 00:14:45 +000086
wdenk57b2d802003-06-27 21:31:46 +000087 /* The GDT table ...
wdenk591dda52002-11-18 00:14:45 +000088 *
Wolfgang Denka1be4762008-05-20 16:00:29 +020089 * Selector Type
90 * 0x00 NULL
91 * 0x08 Unused
wdenk57b2d802003-06-27 21:31:46 +000092 * 0x10 32bit code
wdenk591dda52002-11-18 00:14:45 +000093 * 0x18 32bit data/stack
wdenk591dda52002-11-18 00:14:45 +000094 */
95
96gdt:
Wolfgang Denka1be4762008-05-20 16:00:29 +020097 .word 0, 0, 0, 0 /* NULL */
98 .word 0, 0, 0, 0 /* unused */
wdenk591dda52002-11-18 00:14:45 +000099
Wolfgang Denka1be4762008-05-20 16:00:29 +0200100 .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
101 .word 0 /* base address = 0 */
102 .word 0x9B00 /* code read/exec */
103 .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */
wdenk591dda52002-11-18 00:14:45 +0000104
Wolfgang Denka1be4762008-05-20 16:00:29 +0200105 .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
106 .word 0x0 /* base address = 0 */
107 .word 0x9300 /* data read/write */
108 .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */