blob: 781d32447ba6c53a5fe50cc341b88c36f0be870d [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
wdenk2262cfe2002-11-18 00:14:45 +000011 */
12
wdenk2262cfe2002-11-18 00:14:45 +000013#include <config.h>
14#include <version.h>
Graeme Russ161b3582010-10-07 20:03:29 +110015#include <asm/global_data.h>
Graeme Russ109ad142011-12-31 10:24:36 +110016#include <asm/processor.h>
Graeme Russ0c24c9c2011-02-12 15:11:32 +110017#include <asm/processor-flags.h>
Graeme Russ9e6c5722011-12-31 22:58:15 +110018#include <generated/generic-asm-offsets.h>
wdenk2262cfe2002-11-18 00:14:45 +000019
wdenk2262cfe2002-11-18 00:14:45 +000020.section .text
21.code32
22.globl _start
wdenk8bde7f72003-06-27 21:31:46 +000023.type _start, @function
Graeme Russfea25722011-04-13 19:43:28 +100024.globl _x86boot_start
25_x86boot_start:
Graeme Russ077e1952010-04-24 00:05:42 +100026 /*
27 * This is the fail safe 32-bit bootstrap entry point. The
28 * following code is not executed from a cold-reset (actually, a
29 * lot of it is, but from real-mode after cold reset. It is
30 * repeated here to put the board into a state as close to cold
31 * reset as necessary)
32 */
33 cli
34 cld
35
Graeme Russ2f0e0cd2011-11-08 02:33:23 +000036 /* Turn off cache (this might require a 486-class CPU) */
Graeme Russ077e1952010-04-24 00:05:42 +100037 movl %cr0, %eax
Graeme Russ0c24c9c2011-02-12 15:11:32 +110038 orl $(X86_CR0_NW | X86_CR0_CD), %eax
Graeme Russ077e1952010-04-24 00:05:42 +100039 movl %eax, %cr0
40 wbinvd
41
Gabe Black91d82a22012-11-03 11:41:28 +000042 /* Tell 32-bit code it is being entered from an in-RAM copy */
43 movw $GD_FLG_WARM_BOOT, %bx
44 jmp 1f
wdenk8bde7f72003-06-27 21:31:46 +000045_start:
Gabe Black91d82a22012-11-03 11:41:28 +000046 /*
47 * This is the 32-bit cold-reset entry point. Initialize %bx to 0
48 * in case we're preceeded by some sort of boot stub.
49 */
50 movw $GD_FLG_COLD_BOOT, %bx
511:
Graeme Russ077e1952010-04-24 00:05:42 +100052
Graeme Russdbf71152011-04-13 19:43:26 +100053 /* Load the segement registes to match the gdt loaded in start16.S */
Graeme Russ109ad142011-12-31 10:24:36 +110054 movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax
Graeme Russ8ffb2e82010-10-07 20:03:21 +110055 movw %ax, %fs
56 movw %ax, %ds
57 movw %ax, %gs
58 movw %ax, %es
59 movw %ax, %ss
wdenk8bde7f72003-06-27 21:31:46 +000060
Mike Williams16263082011-07-22 04:01:30 +000061 /* Clear the interrupt vectors */
Graeme Russ077e1952010-04-24 00:05:42 +100062 lidt blank_idt_ptr
63
wdenk2262cfe2002-11-18 00:14:45 +000064 /* Early platform init (setup gpio, etc ) */
wdenk2262cfe2002-11-18 00:14:45 +000065 jmp early_board_init
Graeme Russ88fa0a62010-10-07 20:03:27 +110066.globl early_board_init_ret
wdenk2262cfe2002-11-18 00:14:45 +000067early_board_init_ret:
wdenk8bde7f72003-06-27 21:31:46 +000068
Graeme Russed4cba72011-02-12 15:11:52 +110069 /* Initialise Cache-As-RAM */
70 jmp car_init
71.globl car_init_ret
72car_init_ret:
73 /*
74 * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM,
75 * or fully initialised SDRAM - we really don't care which)
76 * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack
Simon Glass76f90f32014-11-06 13:20:04 -070077 * and early malloc area.
78 *
79 * Stack grows down from top of CAR. We have:
80 *
81 * top-> CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE
82 * global_data
83 * x86 global descriptor table
84 * early malloc area
85 * stack
86 * bottom-> CONFIG_SYS_CAR_ADDR
Graeme Russed4cba72011-02-12 15:11:52 +110087 */
Graeme Russ4e334672011-02-12 15:11:33 +110088
Graeme Russ8d616252012-11-27 15:38:36 +000089 /* Stack grows down from top of CAR */
90 movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE), %esp
91
92 /* Reserve space on stack for global data */
93 subl $GENERATED_GBL_DATA_SIZE, %esp
94
95 /* Align global data to 16-byte boundary */
96 andl $0xfffffff0, %esp
97
Simon Glassfbd72822014-10-10 07:49:15 -060098 /* Zero the global data since it won't happen later */
99 xorl %eax, %eax
100 movl $GENERATED_GBL_DATA_SIZE, %ecx
101 movl %esp, %edi
102 rep stosb
103
Simon Glass76f90f32014-11-06 13:20:04 -0700104 /* Setup first parameter to setup_gdt, pointer to global_data */
Graeme Russ8d616252012-11-27 15:38:36 +0000105 movl %esp, %eax
106
107 /* Reserve space for global descriptor table */
108 subl $X86_GDT_SIZE, %esp
109
Simon Glass76f90f32014-11-06 13:20:04 -0700110 /* Align temporary global descriptor table to 16-byte boundary */
111 andl $0xfffffff0, %esp
112 movl %esp, %ecx
113
Simon Glass5dbcaa22014-10-10 07:49:16 -0600114#if defined(CONFIG_SYS_MALLOC_F_LEN)
115 subl $CONFIG_SYS_MALLOC_F_LEN, %esp
116 movl %eax, %edx
117 addl $GD_MALLOC_BASE, %edx
118 movl %esp, (%edx)
119#endif
120
Graeme Russ8d616252012-11-27 15:38:36 +0000121 /* Align temporary global descriptor table to 16-byte boundary */
122 andl $0xfffffff0, %esp
123
124 /* Set second parameter to setup_gdt */
Simon Glass76f90f32014-11-06 13:20:04 -0700125 movl %ecx, %edx
Graeme Russ8d616252012-11-27 15:38:36 +0000126
Graeme Russ8d616252012-11-27 15:38:36 +0000127 /* Setup global descriptor table so gd->xyz works */
128 call setup_gdt
Graeme Russ9e6c5722011-12-31 22:58:15 +1100129
Graeme Russ96cd6642011-02-12 15:11:54 +1100130 /* Set parameter to board_init_f() to boot flags */
Graeme Russdbf71152011-04-13 19:43:26 +1000131 xorl %eax, %eax
Graeme Russ161b3582010-10-07 20:03:29 +1100132
Graeme Russdbf71152011-04-13 19:43:26 +1000133 /* Enter, U-boot! */
134 call board_init_f
wdenk2262cfe2002-11-18 00:14:45 +0000135
136 /* indicate (lack of) progress */
wdenk8bde7f72003-06-27 21:31:46 +0000137 movw $0x85, %ax
Graeme Russfb002902011-02-12 15:11:58 +1100138 jmp die
139
Graeme Russf48dd6f2012-01-01 15:06:39 +1100140.globl board_init_f_r_trampoline
141.type board_init_f_r_trampoline, @function
142board_init_f_r_trampoline:
Graeme Russfb002902011-02-12 15:11:58 +1100143 /*
144 * SDRAM has been initialised, U-Boot code has been copied into
145 * RAM, BSS has been cleared and relocation adjustments have been
146 * made. It is now time to jump into the in-RAM copy of U-Boot
147 *
Graeme Russf48dd6f2012-01-01 15:06:39 +1100148 * %eax = Address of top of new stack
Graeme Russfb002902011-02-12 15:11:58 +1100149 */
150
Graeme Russ8d616252012-11-27 15:38:36 +0000151 /* Stack grows down from top of SDRAM */
Graeme Russfb002902011-02-12 15:11:58 +1100152 movl %eax, %esp
153
Graeme Russ8d616252012-11-27 15:38:36 +0000154 /* Reserve space on stack for global data */
155 subl $GENERATED_GBL_DATA_SIZE, %esp
156
157 /* Align global data to 16-byte boundary */
158 andl $0xfffffff0, %esp
159
160 /* Setup first parameter to memcpy (and setup_gdt) */
161 movl %esp, %eax
162
163 /* Setup second parameter to memcpy */
164 fs movl 0, %edx
165
166 /* Set third parameter to memcpy */
167 movl $GENERATED_GBL_DATA_SIZE, %ecx
168
169 /* Copy global data from CAR to SDRAM stack */
170 call memcpy
171
172 /* Reserve space for global descriptor table */
173 subl $X86_GDT_SIZE, %esp
174
175 /* Align global descriptor table to 16-byte boundary */
176 andl $0xfffffff0, %esp
177
178 /* Set second parameter to setup_gdt */
179 movl %esp, %edx
180
Graeme Russ8d616252012-11-27 15:38:36 +0000181 /* Setup global descriptor table so gd->xyz works */
182 call setup_gdt
183
Graeme Russf48dd6f2012-01-01 15:06:39 +1100184 /* Re-enter U-Boot by calling board_init_f_r */
185 call board_init_f_r
Graeme Russfb002902011-02-12 15:11:58 +1100186
Graeme Russ2f0e0cd2011-11-08 02:33:23 +0000187die:
188 hlt
wdenk2262cfe2002-11-18 00:14:45 +0000189 jmp die
wdenk8bde7f72003-06-27 21:31:46 +0000190 hlt
Graeme Russ077e1952010-04-24 00:05:42 +1000191
192blank_idt_ptr:
193 .word 0 /* limit */
194 .long 0 /* base */
Graeme Russa206cc22011-11-08 02:33:19 +0000195
196 .p2align 2 /* force 4-byte alignment */
197
198multiboot_header:
199 /* magic */
200 .long 0x1BADB002
201 /* flags */
202 .long (1 << 16)
203 /* checksum */
204 .long -0x1BADB002 - (1 << 16)
205 /* header addr */
206 .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
207 /* load addr */
208 .long CONFIG_SYS_TEXT_BASE
209 /* load end addr */
210 .long 0
211 /* bss end addr */
212 .long 0
213 /* entry addr */
214 .long CONFIG_SYS_TEXT_BASE