blob: ec12e8044fd92a6f4c8fcf24057bb19f3645324f [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
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
wdenk2262cfe2002-11-18 00:14:45 +000029#include <config.h>
30#include <version.h>
Graeme Russ161b3582010-10-07 20:03:29 +110031#include <asm/global_data.h>
Graeme Russ109ad142011-12-31 10:24:36 +110032#include <asm/processor.h>
Graeme Russ0c24c9c2011-02-12 15:11:32 +110033#include <asm/processor-flags.h>
Graeme Russ9e6c5722011-12-31 22:58:15 +110034#include <generated/generic-asm-offsets.h>
wdenk2262cfe2002-11-18 00:14:45 +000035
wdenk2262cfe2002-11-18 00:14:45 +000036.section .text
37.code32
38.globl _start
wdenk8bde7f72003-06-27 21:31:46 +000039.type _start, @function
Graeme Russfea25722011-04-13 19:43:28 +100040.globl _x86boot_start
41_x86boot_start:
Graeme Russ077e1952010-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 Russ2f0e0cd2011-11-08 02:33:23 +000052 /* Turn off cache (this might require a 486-class CPU) */
Graeme Russ077e1952010-04-24 00:05:42 +100053 movl %cr0, %eax
Graeme Russ0c24c9c2011-02-12 15:11:32 +110054 orl $(X86_CR0_NW | X86_CR0_CD), %eax
Graeme Russ077e1952010-04-24 00:05:42 +100055 movl %eax, %cr0
56 wbinvd
57
wdenk8bde7f72003-06-27 21:31:46 +000058_start:
Graeme Russ077e1952010-04-24 00:05:42 +100059 /* This is the 32-bit cold-reset entry point */
60
Graeme Russdbf71152011-04-13 19:43:26 +100061 /* Load the segement registes to match the gdt loaded in start16.S */
Graeme Russ109ad142011-12-31 10:24:36 +110062 movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax
Graeme Russ8ffb2e82010-10-07 20:03:21 +110063 movw %ax, %fs
64 movw %ax, %ds
65 movw %ax, %gs
66 movw %ax, %es
67 movw %ax, %ss
wdenk8bde7f72003-06-27 21:31:46 +000068
Mike Williams16263082011-07-22 04:01:30 +000069 /* Clear the interrupt vectors */
Graeme Russ077e1952010-04-24 00:05:42 +100070 lidt blank_idt_ptr
71
wdenk2262cfe2002-11-18 00:14:45 +000072 /* Early platform init (setup gpio, etc ) */
wdenk2262cfe2002-11-18 00:14:45 +000073 jmp early_board_init
Graeme Russ88fa0a62010-10-07 20:03:27 +110074.globl early_board_init_ret
wdenk2262cfe2002-11-18 00:14:45 +000075early_board_init_ret:
wdenk8bde7f72003-06-27 21:31:46 +000076
Graeme Russed4cba72011-02-12 15:11:52 +110077 /* Initialise Cache-As-RAM */
78 jmp car_init
79.globl car_init_ret
80car_init_ret:
81 /*
82 * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM,
83 * or fully initialised SDRAM - we really don't care which)
84 * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack
85 */
Graeme Russ4e334672011-02-12 15:11:33 +110086
Graeme Russ8d616252012-11-27 15:38:36 +000087 /* Stack grows down from top of CAR */
88 movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE), %esp
89
90 /* Reserve space on stack for global data */
91 subl $GENERATED_GBL_DATA_SIZE, %esp
92
93 /* Align global data to 16-byte boundary */
94 andl $0xfffffff0, %esp
95
96 /* Setup first parameter to setup_gdt */
97 movl %esp, %eax
98
99 /* Reserve space for global descriptor table */
100 subl $X86_GDT_SIZE, %esp
101
102 /* Align temporary global descriptor table to 16-byte boundary */
103 andl $0xfffffff0, %esp
104
105 /* Set second parameter to setup_gdt */
106 movl %esp, %edx
107
108 /* gd->gd_addr = gd (Required to allow gd->xyz to work) */
109 movl %eax, (%eax)
110
111 /* Setup global descriptor table so gd->xyz works */
112 call setup_gdt
Graeme Russ9e6c5722011-12-31 22:58:15 +1100113
Graeme Russ96cd6642011-02-12 15:11:54 +1100114 /* Set parameter to board_init_f() to boot flags */
Graeme Russdbf71152011-04-13 19:43:26 +1000115 xorl %eax, %eax
116 movw %bx, %ax
Graeme Russ161b3582010-10-07 20:03:29 +1100117
Graeme Russdbf71152011-04-13 19:43:26 +1000118 /* Enter, U-boot! */
119 call board_init_f
wdenk2262cfe2002-11-18 00:14:45 +0000120
121 /* indicate (lack of) progress */
wdenk8bde7f72003-06-27 21:31:46 +0000122 movw $0x85, %ax
Graeme Russfb002902011-02-12 15:11:58 +1100123 jmp die
124
Graeme Russf48dd6f2012-01-01 15:06:39 +1100125.globl board_init_f_r_trampoline
126.type board_init_f_r_trampoline, @function
127board_init_f_r_trampoline:
Graeme Russfb002902011-02-12 15:11:58 +1100128 /*
129 * SDRAM has been initialised, U-Boot code has been copied into
130 * RAM, BSS has been cleared and relocation adjustments have been
131 * made. It is now time to jump into the in-RAM copy of U-Boot
132 *
Graeme Russf48dd6f2012-01-01 15:06:39 +1100133 * %eax = Address of top of new stack
Graeme Russfb002902011-02-12 15:11:58 +1100134 */
135
Graeme Russ8d616252012-11-27 15:38:36 +0000136 /* Stack grows down from top of SDRAM */
Graeme Russfb002902011-02-12 15:11:58 +1100137 movl %eax, %esp
138
Graeme Russ8d616252012-11-27 15:38:36 +0000139 /* Reserve space on stack for global data */
140 subl $GENERATED_GBL_DATA_SIZE, %esp
141
142 /* Align global data to 16-byte boundary */
143 andl $0xfffffff0, %esp
144
145 /* Setup first parameter to memcpy (and setup_gdt) */
146 movl %esp, %eax
147
148 /* Setup second parameter to memcpy */
149 fs movl 0, %edx
150
151 /* Set third parameter to memcpy */
152 movl $GENERATED_GBL_DATA_SIZE, %ecx
153
154 /* Copy global data from CAR to SDRAM stack */
155 call memcpy
156
157 /* Reserve space for global descriptor table */
158 subl $X86_GDT_SIZE, %esp
159
160 /* Align global descriptor table to 16-byte boundary */
161 andl $0xfffffff0, %esp
162
163 /* Set second parameter to setup_gdt */
164 movl %esp, %edx
165
166 /* gd->gd_addr = gd (Required to allow gd->xyz to work) */
167 movl %eax, (%eax)
168
169 /* Setup global descriptor table so gd->xyz works */
170 call setup_gdt
171
Graeme Russf48dd6f2012-01-01 15:06:39 +1100172 /* Re-enter U-Boot by calling board_init_f_r */
173 call board_init_f_r
Graeme Russfb002902011-02-12 15:11:58 +1100174
Graeme Russ2f0e0cd2011-11-08 02:33:23 +0000175die:
176 hlt
wdenk2262cfe2002-11-18 00:14:45 +0000177 jmp die
wdenk8bde7f72003-06-27 21:31:46 +0000178 hlt
Graeme Russ077e1952010-04-24 00:05:42 +1000179
180blank_idt_ptr:
181 .word 0 /* limit */
182 .long 0 /* base */
Graeme Russa206cc22011-11-08 02:33:19 +0000183
184 .p2align 2 /* force 4-byte alignment */
185
186multiboot_header:
187 /* magic */
188 .long 0x1BADB002
189 /* flags */
190 .long (1 << 16)
191 /* checksum */
192 .long -0x1BADB002 - (1 << 16)
193 /* header addr */
194 .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
195 /* load addr */
196 .long CONFIG_SYS_TEXT_BASE
197 /* load end addr */
198 .long 0
199 /* bss end addr */
200 .long 0
201 /* entry addr */
202 .long CONFIG_SYS_TEXT_BASE