blob: f389584567cf2823e64e3ed515823585d7875802 [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
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02008 * 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
wdenk591dda52002-11-18 00:14:45 +000029#include <config.h>
30#include <version.h>
Graeme Russ5fb91cc2010-10-07 20:03:29 +110031#include <asm/global_data.h>
Graeme Russ391bb952011-12-31 10:24:36 +110032#include <asm/processor.h>
Graeme Russ93efcb22011-02-12 15:11:32 +110033#include <asm/processor-flags.h>
Graeme Russ35368962011-12-31 22:58:15 +110034#include <generated/generic-asm-offsets.h>
wdenk591dda52002-11-18 00:14:45 +000035
wdenk591dda52002-11-18 00:14:45 +000036.section .text
37.code32
38.globl _start
wdenk57b2d802003-06-27 21:31:46 +000039.type _start, @function
Graeme Russcbfce1d2011-04-13 19:43:28 +100040.globl _x86boot_start
41_x86boot_start:
Graeme Russ8accbb92010-04-24 00:05:42 +100042 /*
43 * This is the fail safe 32-bit bootstrap entry point. The
44 * following code is not executed from a cold-reset (actually, a
45 * lot of it is, but from real-mode after cold reset. It is
46 * repeated here to put the board into a state as close to cold
47 * reset as necessary)
48 */
49 cli
50 cld
51
Graeme Russc379b5d2011-11-08 02:33:23 +000052 /* Turn off cache (this might require a 486-class CPU) */
Graeme Russ8accbb92010-04-24 00:05:42 +100053 movl %cr0, %eax
Graeme Russ93efcb22011-02-12 15:11:32 +110054 orl $(X86_CR0_NW | X86_CR0_CD), %eax
Graeme Russ8accbb92010-04-24 00:05:42 +100055 movl %eax, %cr0
56 wbinvd
57
Gabe Blackef899322012-11-03 11:41:28 +000058 /* Tell 32-bit code it is being entered from an in-RAM copy */
59 movw $GD_FLG_WARM_BOOT, %bx
60 jmp 1f
wdenk57b2d802003-06-27 21:31:46 +000061_start:
Gabe Blackef899322012-11-03 11:41:28 +000062 /*
63 * This is the 32-bit cold-reset entry point. Initialize %bx to 0
64 * in case we're preceeded by some sort of boot stub.
65 */
66 movw $GD_FLG_COLD_BOOT, %bx
671:
Graeme Russ8accbb92010-04-24 00:05:42 +100068
Graeme Russ45fc1d82011-04-13 19:43:26 +100069 /* Load the segement registes to match the gdt loaded in start16.S */
Graeme Russ391bb952011-12-31 10:24:36 +110070 movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax
Graeme Russ3e6ec382010-10-07 20:03:21 +110071 movw %ax, %fs
72 movw %ax, %ds
73 movw %ax, %gs
74 movw %ax, %es
75 movw %ax, %ss
wdenk57b2d802003-06-27 21:31:46 +000076
Mike Williamsbf895ad2011-07-22 04:01:30 +000077 /* Clear the interrupt vectors */
Graeme Russ8accbb92010-04-24 00:05:42 +100078 lidt blank_idt_ptr
79
wdenk591dda52002-11-18 00:14:45 +000080 /* Early platform init (setup gpio, etc ) */
wdenk591dda52002-11-18 00:14:45 +000081 jmp early_board_init
Graeme Russ157b0e92010-10-07 20:03:27 +110082.globl early_board_init_ret
wdenk591dda52002-11-18 00:14:45 +000083early_board_init_ret:
wdenk57b2d802003-06-27 21:31:46 +000084
Graeme Russbc761932011-02-12 15:11:52 +110085 /* Initialise Cache-As-RAM */
86 jmp car_init
87.globl car_init_ret
88car_init_ret:
89 /*
90 * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM,
91 * or fully initialised SDRAM - we really don't care which)
92 * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack
93 */
Graeme Russb39f12f2010-04-24 00:05:41 +100094
Graeme Russ007818a2012-11-27 15:38:36 +000095 /* Stack grows down from top of CAR */
96 movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE), %esp
97
98 /* Reserve space on stack for global data */
99 subl $GENERATED_GBL_DATA_SIZE, %esp
100
101 /* Align global data to 16-byte boundary */
102 andl $0xfffffff0, %esp
103
104 /* Setup first parameter to setup_gdt */
105 movl %esp, %eax
106
107 /* Reserve space for global descriptor table */
108 subl $X86_GDT_SIZE, %esp
109
110 /* Align temporary global descriptor table to 16-byte boundary */
111 andl $0xfffffff0, %esp
112
113 /* Set second parameter to setup_gdt */
114 movl %esp, %edx
115
Graeme Russ007818a2012-11-27 15:38:36 +0000116 /* Setup global descriptor table so gd->xyz works */
117 call setup_gdt
Graeme Russ35368962011-12-31 22:58:15 +1100118
Graeme Russ38183932011-02-12 15:11:54 +1100119 /* Set parameter to board_init_f() to boot flags */
Graeme Russ45fc1d82011-04-13 19:43:26 +1000120 xorl %eax, %eax
121 movw %bx, %ax
Graeme Russ5fb91cc2010-10-07 20:03:29 +1100122
Graeme Russ45fc1d82011-04-13 19:43:26 +1000123 /* Enter, U-boot! */
124 call board_init_f
wdenk591dda52002-11-18 00:14:45 +0000125
126 /* indicate (lack of) progress */
wdenk57b2d802003-06-27 21:31:46 +0000127 movw $0x85, %ax
Graeme Russ9c44afc2011-02-12 15:11:58 +1100128 jmp die
129
Graeme Russd7755b42012-01-01 15:06:39 +1100130.globl board_init_f_r_trampoline
131.type board_init_f_r_trampoline, @function
132board_init_f_r_trampoline:
Graeme Russ9c44afc2011-02-12 15:11:58 +1100133 /*
134 * SDRAM has been initialised, U-Boot code has been copied into
135 * RAM, BSS has been cleared and relocation adjustments have been
136 * made. It is now time to jump into the in-RAM copy of U-Boot
137 *
Graeme Russd7755b42012-01-01 15:06:39 +1100138 * %eax = Address of top of new stack
Graeme Russ9c44afc2011-02-12 15:11:58 +1100139 */
140
Graeme Russ007818a2012-11-27 15:38:36 +0000141 /* Stack grows down from top of SDRAM */
Graeme Russ9c44afc2011-02-12 15:11:58 +1100142 movl %eax, %esp
143
Graeme Russ007818a2012-11-27 15:38:36 +0000144 /* Reserve space on stack for global data */
145 subl $GENERATED_GBL_DATA_SIZE, %esp
146
147 /* Align global data to 16-byte boundary */
148 andl $0xfffffff0, %esp
149
150 /* Setup first parameter to memcpy (and setup_gdt) */
151 movl %esp, %eax
152
153 /* Setup second parameter to memcpy */
154 fs movl 0, %edx
155
156 /* Set third parameter to memcpy */
157 movl $GENERATED_GBL_DATA_SIZE, %ecx
158
159 /* Copy global data from CAR to SDRAM stack */
160 call memcpy
161
162 /* Reserve space for global descriptor table */
163 subl $X86_GDT_SIZE, %esp
164
165 /* Align global descriptor table to 16-byte boundary */
166 andl $0xfffffff0, %esp
167
168 /* Set second parameter to setup_gdt */
169 movl %esp, %edx
170
Graeme Russ007818a2012-11-27 15:38:36 +0000171 /* Setup global descriptor table so gd->xyz works */
172 call setup_gdt
173
Graeme Russd7755b42012-01-01 15:06:39 +1100174 /* Re-enter U-Boot by calling board_init_f_r */
175 call board_init_f_r
Graeme Russ9c44afc2011-02-12 15:11:58 +1100176
Graeme Russc379b5d2011-11-08 02:33:23 +0000177die:
178 hlt
wdenk591dda52002-11-18 00:14:45 +0000179 jmp die
wdenk57b2d802003-06-27 21:31:46 +0000180 hlt
Graeme Russ8accbb92010-04-24 00:05:42 +1000181
182blank_idt_ptr:
183 .word 0 /* limit */
184 .long 0 /* base */
Graeme Russ786c3952011-11-08 02:33:19 +0000185
186 .p2align 2 /* force 4-byte alignment */
187
188multiboot_header:
189 /* magic */
190 .long 0x1BADB002
191 /* flags */
192 .long (1 << 16)
193 /* checksum */
194 .long -0x1BADB002 - (1 << 16)
195 /* header addr */
196 .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
197 /* load addr */
198 .long CONFIG_SYS_TEXT_BASE
199 /* load end addr */
200 .long 0
201 /* bss end addr */
202 .long 0
203 /* entry addr */
204 .long CONFIG_SYS_TEXT_BASE