wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
Graeme Russ | fea2572 | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 2 | * U-boot - x86 Startup Code |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 3 | * |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 4 | * (C) Copyright 2008-2011 |
| 5 | * Graeme Russ, <graeme.russ@gmail.com> |
| 6 | * |
| 7 | * (C) Copyright 2002 |
Albert ARIBAUD | fa82f87 | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 8 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 9 | * |
| 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 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 29 | #include <config.h> |
| 30 | #include <version.h> |
Graeme Russ | 161b358 | 2010-10-07 20:03:29 +1100 | [diff] [blame] | 31 | #include <asm/global_data.h> |
Graeme Russ | 109ad14 | 2011-12-31 10:24:36 +1100 | [diff] [blame] | 32 | #include <asm/processor.h> |
Graeme Russ | 0c24c9c | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 33 | #include <asm/processor-flags.h> |
Graeme Russ | 9e6c572 | 2011-12-31 22:58:15 +1100 | [diff] [blame] | 34 | #include <generated/generic-asm-offsets.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 35 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 36 | .section .text |
| 37 | .code32 |
| 38 | .globl _start |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 39 | .type _start, @function |
Graeme Russ | fea2572 | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 40 | .globl _x86boot_start |
| 41 | _x86boot_start: |
Graeme Russ | 077e195 | 2010-04-24 00:05:42 +1000 | [diff] [blame] | 42 | /* |
| 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 Russ | 2f0e0cd | 2011-11-08 02:33:23 +0000 | [diff] [blame] | 52 | /* Turn off cache (this might require a 486-class CPU) */ |
Graeme Russ | 077e195 | 2010-04-24 00:05:42 +1000 | [diff] [blame] | 53 | movl %cr0, %eax |
Graeme Russ | 0c24c9c | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 54 | orl $(X86_CR0_NW | X86_CR0_CD), %eax |
Graeme Russ | 077e195 | 2010-04-24 00:05:42 +1000 | [diff] [blame] | 55 | movl %eax, %cr0 |
| 56 | wbinvd |
| 57 | |
Gabe Black | 91d82a2 | 2012-11-03 11:41:28 +0000 | [diff] [blame^] | 58 | /* Tell 32-bit code it is being entered from an in-RAM copy */ |
| 59 | movw $GD_FLG_WARM_BOOT, %bx |
| 60 | jmp 1f |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 61 | _start: |
Gabe Black | 91d82a2 | 2012-11-03 11:41:28 +0000 | [diff] [blame^] | 62 | /* |
| 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 |
| 67 | 1: |
Graeme Russ | 077e195 | 2010-04-24 00:05:42 +1000 | [diff] [blame] | 68 | |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 69 | /* Load the segement registes to match the gdt loaded in start16.S */ |
Graeme Russ | 109ad14 | 2011-12-31 10:24:36 +1100 | [diff] [blame] | 70 | movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 71 | movw %ax, %fs |
| 72 | movw %ax, %ds |
| 73 | movw %ax, %gs |
| 74 | movw %ax, %es |
| 75 | movw %ax, %ss |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 76 | |
Mike Williams | 1626308 | 2011-07-22 04:01:30 +0000 | [diff] [blame] | 77 | /* Clear the interrupt vectors */ |
Graeme Russ | 077e195 | 2010-04-24 00:05:42 +1000 | [diff] [blame] | 78 | lidt blank_idt_ptr |
| 79 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 80 | /* Early platform init (setup gpio, etc ) */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 81 | jmp early_board_init |
Graeme Russ | 88fa0a6 | 2010-10-07 20:03:27 +1100 | [diff] [blame] | 82 | .globl early_board_init_ret |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 83 | early_board_init_ret: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 84 | |
Graeme Russ | ed4cba7 | 2011-02-12 15:11:52 +1100 | [diff] [blame] | 85 | /* Initialise Cache-As-RAM */ |
| 86 | jmp car_init |
| 87 | .globl car_init_ret |
| 88 | car_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 Russ | 4e33467 | 2011-02-12 15:11:33 +1100 | [diff] [blame] | 94 | |
Graeme Russ | 8d61625 | 2012-11-27 15:38:36 +0000 | [diff] [blame] | 95 | /* 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 | |
| 116 | /* gd->gd_addr = gd (Required to allow gd->xyz to work) */ |
| 117 | movl %eax, (%eax) |
| 118 | |
| 119 | /* Setup global descriptor table so gd->xyz works */ |
| 120 | call setup_gdt |
Graeme Russ | 9e6c572 | 2011-12-31 22:58:15 +1100 | [diff] [blame] | 121 | |
Graeme Russ | 96cd664 | 2011-02-12 15:11:54 +1100 | [diff] [blame] | 122 | /* Set parameter to board_init_f() to boot flags */ |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 123 | xorl %eax, %eax |
| 124 | movw %bx, %ax |
Graeme Russ | 161b358 | 2010-10-07 20:03:29 +1100 | [diff] [blame] | 125 | |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 126 | /* Enter, U-boot! */ |
| 127 | call board_init_f |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 128 | |
| 129 | /* indicate (lack of) progress */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 130 | movw $0x85, %ax |
Graeme Russ | fb00290 | 2011-02-12 15:11:58 +1100 | [diff] [blame] | 131 | jmp die |
| 132 | |
Graeme Russ | f48dd6f | 2012-01-01 15:06:39 +1100 | [diff] [blame] | 133 | .globl board_init_f_r_trampoline |
| 134 | .type board_init_f_r_trampoline, @function |
| 135 | board_init_f_r_trampoline: |
Graeme Russ | fb00290 | 2011-02-12 15:11:58 +1100 | [diff] [blame] | 136 | /* |
| 137 | * SDRAM has been initialised, U-Boot code has been copied into |
| 138 | * RAM, BSS has been cleared and relocation adjustments have been |
| 139 | * made. It is now time to jump into the in-RAM copy of U-Boot |
| 140 | * |
Graeme Russ | f48dd6f | 2012-01-01 15:06:39 +1100 | [diff] [blame] | 141 | * %eax = Address of top of new stack |
Graeme Russ | fb00290 | 2011-02-12 15:11:58 +1100 | [diff] [blame] | 142 | */ |
| 143 | |
Graeme Russ | 8d61625 | 2012-11-27 15:38:36 +0000 | [diff] [blame] | 144 | /* Stack grows down from top of SDRAM */ |
Graeme Russ | fb00290 | 2011-02-12 15:11:58 +1100 | [diff] [blame] | 145 | movl %eax, %esp |
| 146 | |
Graeme Russ | 8d61625 | 2012-11-27 15:38:36 +0000 | [diff] [blame] | 147 | /* Reserve space on stack for global data */ |
| 148 | subl $GENERATED_GBL_DATA_SIZE, %esp |
| 149 | |
| 150 | /* Align global data to 16-byte boundary */ |
| 151 | andl $0xfffffff0, %esp |
| 152 | |
| 153 | /* Setup first parameter to memcpy (and setup_gdt) */ |
| 154 | movl %esp, %eax |
| 155 | |
| 156 | /* Setup second parameter to memcpy */ |
| 157 | fs movl 0, %edx |
| 158 | |
| 159 | /* Set third parameter to memcpy */ |
| 160 | movl $GENERATED_GBL_DATA_SIZE, %ecx |
| 161 | |
| 162 | /* Copy global data from CAR to SDRAM stack */ |
| 163 | call memcpy |
| 164 | |
| 165 | /* Reserve space for global descriptor table */ |
| 166 | subl $X86_GDT_SIZE, %esp |
| 167 | |
| 168 | /* Align global descriptor table to 16-byte boundary */ |
| 169 | andl $0xfffffff0, %esp |
| 170 | |
| 171 | /* Set second parameter to setup_gdt */ |
| 172 | movl %esp, %edx |
| 173 | |
| 174 | /* gd->gd_addr = gd (Required to allow gd->xyz to work) */ |
| 175 | movl %eax, (%eax) |
| 176 | |
| 177 | /* Setup global descriptor table so gd->xyz works */ |
| 178 | call setup_gdt |
| 179 | |
Graeme Russ | f48dd6f | 2012-01-01 15:06:39 +1100 | [diff] [blame] | 180 | /* Re-enter U-Boot by calling board_init_f_r */ |
| 181 | call board_init_f_r |
Graeme Russ | fb00290 | 2011-02-12 15:11:58 +1100 | [diff] [blame] | 182 | |
Graeme Russ | 2f0e0cd | 2011-11-08 02:33:23 +0000 | [diff] [blame] | 183 | die: |
| 184 | hlt |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 185 | jmp die |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 186 | hlt |
Graeme Russ | 077e195 | 2010-04-24 00:05:42 +1000 | [diff] [blame] | 187 | |
| 188 | blank_idt_ptr: |
| 189 | .word 0 /* limit */ |
| 190 | .long 0 /* base */ |
Graeme Russ | a206cc2 | 2011-11-08 02:33:19 +0000 | [diff] [blame] | 191 | |
| 192 | .p2align 2 /* force 4-byte alignment */ |
| 193 | |
| 194 | multiboot_header: |
| 195 | /* magic */ |
| 196 | .long 0x1BADB002 |
| 197 | /* flags */ |
| 198 | .long (1 << 16) |
| 199 | /* checksum */ |
| 200 | .long -0x1BADB002 - (1 << 16) |
| 201 | /* header addr */ |
| 202 | .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE |
| 203 | /* load addr */ |
| 204 | .long CONFIG_SYS_TEXT_BASE |
| 205 | /* load end addr */ |
| 206 | .long 0 |
| 207 | /* bss end addr */ |
| 208 | .long 0 |
| 209 | /* entry addr */ |
| 210 | .long CONFIG_SYS_TEXT_BASE |