wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
Graeme Russ | cbfce1d | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 2 | * U-boot - x86 Startup Code |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 3 | * |
Graeme Russ | 45fc1d8 | 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 | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 8 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | 591dda5 | 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 | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 29 | #include <config.h> |
| 30 | #include <version.h> |
Graeme Russ | 5fb91cc | 2010-10-07 20:03:29 +1100 | [diff] [blame] | 31 | #include <asm/global_data.h> |
Graeme Russ | 93efcb2 | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 32 | #include <asm/processor-flags.h> |
Graeme Russ | c6512ca | 2011-11-08 02:33:18 +0000 | [diff] [blame] | 33 | #include <generated/asm-offsets.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 34 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 35 | .section .text |
| 36 | .code32 |
| 37 | .globl _start |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 38 | .type _start, @function |
Graeme Russ | cbfce1d | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 39 | .globl _x86boot_start |
| 40 | _x86boot_start: |
Graeme Russ | 8accbb9 | 2010-04-24 00:05:42 +1000 | [diff] [blame] | 41 | /* |
| 42 | * This is the fail safe 32-bit bootstrap entry point. The |
| 43 | * following code is not executed from a cold-reset (actually, a |
| 44 | * lot of it is, but from real-mode after cold reset. It is |
| 45 | * repeated here to put the board into a state as close to cold |
| 46 | * reset as necessary) |
| 47 | */ |
| 48 | cli |
| 49 | cld |
| 50 | |
| 51 | /* Turn of cache (this might require a 486-class CPU) */ |
| 52 | movl %cr0, %eax |
Graeme Russ | 93efcb2 | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 53 | orl $(X86_CR0_NW | X86_CR0_CD), %eax |
Graeme Russ | 8accbb9 | 2010-04-24 00:05:42 +1000 | [diff] [blame] | 54 | movl %eax, %cr0 |
| 55 | wbinvd |
| 56 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 57 | _start: |
Graeme Russ | 8accbb9 | 2010-04-24 00:05:42 +1000 | [diff] [blame] | 58 | /* This is the 32-bit cold-reset entry point */ |
| 59 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 60 | /* Load the segement registes to match the gdt loaded in start16.S */ |
| 61 | movl $0x18, %eax |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 62 | movw %ax, %fs |
| 63 | movw %ax, %ds |
| 64 | movw %ax, %gs |
| 65 | movw %ax, %es |
| 66 | movw %ax, %ss |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 67 | |
Mike Williams | bf895ad | 2011-07-22 04:01:30 +0000 | [diff] [blame] | 68 | /* Clear the interrupt vectors */ |
Graeme Russ | 8accbb9 | 2010-04-24 00:05:42 +1000 | [diff] [blame] | 69 | lidt blank_idt_ptr |
| 70 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 71 | /* Early platform init (setup gpio, etc ) */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 72 | jmp early_board_init |
Graeme Russ | 157b0e9 | 2010-10-07 20:03:27 +1100 | [diff] [blame] | 73 | .globl early_board_init_ret |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 74 | early_board_init_ret: |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 75 | |
Graeme Russ | bc76193 | 2011-02-12 15:11:52 +1100 | [diff] [blame] | 76 | /* Initialise Cache-As-RAM */ |
| 77 | jmp car_init |
| 78 | .globl car_init_ret |
| 79 | car_init_ret: |
| 80 | /* |
| 81 | * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM, |
| 82 | * or fully initialised SDRAM - we really don't care which) |
| 83 | * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack |
| 84 | */ |
| 85 | movl $CONFIG_SYS_INIT_SP_ADDR, %esp |
Graeme Russ | b39f12f | 2010-04-24 00:05:41 +1000 | [diff] [blame] | 86 | |
Graeme Russ | 3818393 | 2011-02-12 15:11:54 +1100 | [diff] [blame] | 87 | /* Set parameter to board_init_f() to boot flags */ |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 88 | xorl %eax, %eax |
| 89 | movw %bx, %ax |
Graeme Russ | 5fb91cc | 2010-10-07 20:03:29 +1100 | [diff] [blame] | 90 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 91 | /* Enter, U-boot! */ |
| 92 | call board_init_f |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 93 | |
| 94 | /* indicate (lack of) progress */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 95 | movw $0x85, %ax |
Graeme Russ | 9c44afc | 2011-02-12 15:11:58 +1100 | [diff] [blame] | 96 | jmp die |
| 97 | |
| 98 | .globl relocate_code |
| 99 | .type relocate_code, @function |
| 100 | relocate_code: |
| 101 | /* |
| 102 | * SDRAM has been initialised, U-Boot code has been copied into |
| 103 | * RAM, BSS has been cleared and relocation adjustments have been |
| 104 | * made. It is now time to jump into the in-RAM copy of U-Boot |
| 105 | * |
| 106 | * %eax = Address of top of stack |
| 107 | * %edx = Address of Global Data |
| 108 | * %ecx = Base address of in-RAM copy of U-Boot |
| 109 | */ |
| 110 | |
| 111 | /* Setup stack in RAM */ |
| 112 | movl %eax, %esp |
| 113 | |
| 114 | /* Setup call address of in-RAM copy of board_init_r() */ |
| 115 | movl $board_init_r, %ebp |
Graeme Russ | c6512ca | 2011-11-08 02:33:18 +0000 | [diff] [blame] | 116 | addl (GENERATED_GD_RELOC_OFF)(%edx), %ebp |
Graeme Russ | 9c44afc | 2011-02-12 15:11:58 +1100 | [diff] [blame] | 117 | |
| 118 | /* Setup parameters to board_init_r() */ |
| 119 | movl %edx, %eax |
| 120 | movl %ecx, %edx |
| 121 | |
| 122 | /* Jump to in-RAM copy of board_init_r() */ |
| 123 | call *%ebp |
| 124 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 125 | die: hlt |
| 126 | jmp die |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 127 | hlt |
Graeme Russ | 8accbb9 | 2010-04-24 00:05:42 +1000 | [diff] [blame] | 128 | |
| 129 | blank_idt_ptr: |
| 130 | .word 0 /* limit */ |
| 131 | .long 0 /* base */ |
Graeme Russ | 786c395 | 2011-11-08 02:33:19 +0000 | [diff] [blame] | 132 | |
| 133 | .p2align 2 /* force 4-byte alignment */ |
| 134 | |
| 135 | multiboot_header: |
| 136 | /* magic */ |
| 137 | .long 0x1BADB002 |
| 138 | /* flags */ |
| 139 | .long (1 << 16) |
| 140 | /* checksum */ |
| 141 | .long -0x1BADB002 - (1 << 16) |
| 142 | /* header addr */ |
| 143 | .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE |
| 144 | /* load addr */ |
| 145 | .long CONFIG_SYS_TEXT_BASE |
| 146 | /* load end addr */ |
| 147 | .long 0 |
| 148 | /* bss end addr */ |
| 149 | .long 0 |
| 150 | /* entry addr */ |
| 151 | .long CONFIG_SYS_TEXT_BASE |