1fea25720SGraeme Russ/* 2fea25720SGraeme Russ * U-boot - x86 Startup Code 3fea25720SGraeme Russ * 4fea25720SGraeme Russ * (C) Copyright 2008-2011 5fea25720SGraeme Russ * Graeme Russ, <graeme.russ@gmail.com> 6fea25720SGraeme Russ * 7fea25720SGraeme Russ * (C) Copyright 2002 8fa82f871SAlbert ARIBAUD * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> 9fea25720SGraeme Russ * 101a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 11fea25720SGraeme Russ */ 12fea25720SGraeme Russ 13fea25720SGraeme Russ#include <config.h> 14fea25720SGraeme Russ#include <version.h> 15fea25720SGraeme Russ#include <asm/global_data.h> 16*d1cd0459SSimon Glass#include <asm/post.h> 17109ad143SGraeme Russ#include <asm/processor.h> 18fea25720SGraeme Russ#include <asm/processor-flags.h> 199e6c572fSGraeme Russ#include <generated/generic-asm-offsets.h> 20fea25720SGraeme Russ 21fea25720SGraeme Russ.section .text 22fea25720SGraeme Russ.code32 23fea25720SGraeme Russ.globl _start 24fea25720SGraeme Russ.type _start, @function 25fea25720SGraeme Russ.globl _x86boot_start 26fea25720SGraeme Russ_x86boot_start: 27fea25720SGraeme Russ /* 28fea25720SGraeme Russ * This is the fail safe 32-bit bootstrap entry point. The 29fea25720SGraeme Russ * following code is not executed from a cold-reset (actually, a 30fea25720SGraeme Russ * lot of it is, but from real-mode after cold reset. It is 31fea25720SGraeme Russ * repeated here to put the board into a state as close to cold 32fea25720SGraeme Russ * reset as necessary) 33fea25720SGraeme Russ */ 34fea25720SGraeme Russ cli 35fea25720SGraeme Russ cld 36fea25720SGraeme Russ 372f0e0cd2SGraeme Russ /* Turn off cache (this might require a 486-class CPU) */ 38fea25720SGraeme Russ movl %cr0, %eax 39fea25720SGraeme Russ orl $(X86_CR0_NW | X86_CR0_CD), %eax 40fea25720SGraeme Russ movl %eax, %cr0 41fea25720SGraeme Russ wbinvd 42fea25720SGraeme Russ 4391d82a29SGabe Black /* Tell 32-bit code it is being entered from an in-RAM copy */ 4491d82a29SGabe Black movw $GD_FLG_WARM_BOOT, %bx 4591d82a29SGabe Black jmp 1f 46fea25720SGraeme Russ_start: 4791d82a29SGabe Black /* 4891d82a29SGabe Black * This is the 32-bit cold-reset entry point. Initialize %bx to 0 4991d82a29SGabe Black * in case we're preceeded by some sort of boot stub. 5091d82a29SGabe Black */ 5191d82a29SGabe Black movw $GD_FLG_COLD_BOOT, %bx 5291d82a29SGabe Black1: 53f67cd51eSSimon Glass /* Save BIST */ 54f67cd51eSSimon Glass movl %eax, %ebp 55fea25720SGraeme Russ 56fea25720SGraeme Russ /* Load the segement registes to match the gdt loaded in start16.S */ 57109ad143SGraeme Russ movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax 58fea25720SGraeme Russ movw %ax, %fs 59fea25720SGraeme Russ movw %ax, %ds 60fea25720SGraeme Russ movw %ax, %gs 61fea25720SGraeme Russ movw %ax, %es 62fea25720SGraeme Russ movw %ax, %ss 63fea25720SGraeme Russ 6416263087SMike Williams /* Clear the interrupt vectors */ 65fea25720SGraeme Russ lidt blank_idt_ptr 66fea25720SGraeme Russ 67fea25720SGraeme Russ /* Early platform init (setup gpio, etc ) */ 68fea25720SGraeme Russ jmp early_board_init 69fea25720SGraeme Russ.globl early_board_init_ret 70fea25720SGraeme Russearly_board_init_ret: 71*d1cd0459SSimon Glass post_code(POST_START) 72fea25720SGraeme Russ 73fea25720SGraeme Russ /* Initialise Cache-As-RAM */ 74fea25720SGraeme Russ jmp car_init 75fea25720SGraeme Russ.globl car_init_ret 76fea25720SGraeme Russcar_init_ret: 77fea25720SGraeme Russ /* 78fea25720SGraeme Russ * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM, 79fea25720SGraeme Russ * or fully initialised SDRAM - we really don't care which) 80fea25720SGraeme Russ * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack 8176f90f30SSimon Glass * and early malloc area. 8276f90f30SSimon Glass * 8376f90f30SSimon Glass * Stack grows down from top of CAR. We have: 8476f90f30SSimon Glass * 8576f90f30SSimon Glass * top-> CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE 8676f90f30SSimon Glass * global_data 8776f90f30SSimon Glass * x86 global descriptor table 8876f90f30SSimon Glass * early malloc area 8976f90f30SSimon Glass * stack 9076f90f30SSimon Glass * bottom-> CONFIG_SYS_CAR_ADDR 91fea25720SGraeme Russ */ 92fea25720SGraeme Russ 938d61625dSGraeme Russ /* Stack grows down from top of CAR */ 948d61625dSGraeme Russ movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE), %esp 958d61625dSGraeme Russ 968d61625dSGraeme Russ /* Reserve space on stack for global data */ 978d61625dSGraeme Russ subl $GENERATED_GBL_DATA_SIZE, %esp 988d61625dSGraeme Russ 998d61625dSGraeme Russ /* Align global data to 16-byte boundary */ 1008d61625dSGraeme Russ andl $0xfffffff0, %esp 101*d1cd0459SSimon Glass post_code(POST_START_STACK) 1028d61625dSGraeme Russ 103fbd72824SSimon Glass /* Zero the global data since it won't happen later */ 104fbd72824SSimon Glass xorl %eax, %eax 105fbd72824SSimon Glass movl $GENERATED_GBL_DATA_SIZE, %ecx 106fbd72824SSimon Glass movl %esp, %edi 107fbd72824SSimon Glass rep stosb 108fbd72824SSimon Glass 10976f90f30SSimon Glass /* Setup first parameter to setup_gdt, pointer to global_data */ 1108d61625dSGraeme Russ movl %esp, %eax 1118d61625dSGraeme Russ 1128d61625dSGraeme Russ /* Reserve space for global descriptor table */ 1138d61625dSGraeme Russ subl $X86_GDT_SIZE, %esp 1148d61625dSGraeme Russ 11576f90f30SSimon Glass /* Align temporary global descriptor table to 16-byte boundary */ 11676f90f30SSimon Glass andl $0xfffffff0, %esp 11776f90f30SSimon Glass movl %esp, %ecx 11876f90f30SSimon Glass 1195dbcaa21SSimon Glass#if defined(CONFIG_SYS_MALLOC_F_LEN) 1205dbcaa21SSimon Glass subl $CONFIG_SYS_MALLOC_F_LEN, %esp 1215dbcaa21SSimon Glass movl %eax, %edx 1225dbcaa21SSimon Glass addl $GD_MALLOC_BASE, %edx 1235dbcaa21SSimon Glass movl %esp, (%edx) 1245dbcaa21SSimon Glass#endif 125f67cd51eSSimon Glass /* Store BIST */ 126f67cd51eSSimon Glass movl %eax, %edx 127f67cd51eSSimon Glass addl $GD_BIST, %edx 128f67cd51eSSimon Glass movl %ebp, (%edx) 1298d61625dSGraeme Russ 1308d61625dSGraeme Russ /* Set second parameter to setup_gdt */ 13176f90f30SSimon Glass movl %ecx, %edx 1328d61625dSGraeme Russ 1338d61625dSGraeme Russ /* Setup global descriptor table so gd->xyz works */ 1348d61625dSGraeme Russ call setup_gdt 1359e6c572fSGraeme Russ 136fea25720SGraeme Russ /* Set parameter to board_init_f() to boot flags */ 137*d1cd0459SSimon Glass post_code(POST_START_DONE) 138fea25720SGraeme Russ xorl %eax, %eax 139fea25720SGraeme Russ 140fea25720SGraeme Russ /* Enter, U-boot! */ 141fea25720SGraeme Russ call board_init_f 142fea25720SGraeme Russ 143fea25720SGraeme Russ /* indicate (lack of) progress */ 144fea25720SGraeme Russ movw $0x85, %ax 145fea25720SGraeme Russ jmp die 146fea25720SGraeme Russ 147f48dd6fcSGraeme Russ.globl board_init_f_r_trampoline 148f48dd6fcSGraeme Russ.type board_init_f_r_trampoline, @function 149f48dd6fcSGraeme Russboard_init_f_r_trampoline: 150fea25720SGraeme Russ /* 151fea25720SGraeme Russ * SDRAM has been initialised, U-Boot code has been copied into 152fea25720SGraeme Russ * RAM, BSS has been cleared and relocation adjustments have been 153fea25720SGraeme Russ * made. It is now time to jump into the in-RAM copy of U-Boot 154fea25720SGraeme Russ * 155f48dd6fcSGraeme Russ * %eax = Address of top of new stack 156fea25720SGraeme Russ */ 157fea25720SGraeme Russ 1588d61625dSGraeme Russ /* Stack grows down from top of SDRAM */ 159fea25720SGraeme Russ movl %eax, %esp 160fea25720SGraeme Russ 1618d61625dSGraeme Russ /* Reserve space on stack for global data */ 1628d61625dSGraeme Russ subl $GENERATED_GBL_DATA_SIZE, %esp 1638d61625dSGraeme Russ 1648d61625dSGraeme Russ /* Align global data to 16-byte boundary */ 1658d61625dSGraeme Russ andl $0xfffffff0, %esp 1668d61625dSGraeme Russ 1678d61625dSGraeme Russ /* Setup first parameter to memcpy (and setup_gdt) */ 1688d61625dSGraeme Russ movl %esp, %eax 1698d61625dSGraeme Russ 1708d61625dSGraeme Russ /* Setup second parameter to memcpy */ 1718d61625dSGraeme Russ fs movl 0, %edx 1728d61625dSGraeme Russ 1738d61625dSGraeme Russ /* Set third parameter to memcpy */ 1748d61625dSGraeme Russ movl $GENERATED_GBL_DATA_SIZE, %ecx 1758d61625dSGraeme Russ 1768d61625dSGraeme Russ /* Copy global data from CAR to SDRAM stack */ 1778d61625dSGraeme Russ call memcpy 1788d61625dSGraeme Russ 1798d61625dSGraeme Russ /* Reserve space for global descriptor table */ 1808d61625dSGraeme Russ subl $X86_GDT_SIZE, %esp 1818d61625dSGraeme Russ 1828d61625dSGraeme Russ /* Align global descriptor table to 16-byte boundary */ 1838d61625dSGraeme Russ andl $0xfffffff0, %esp 1848d61625dSGraeme Russ 1858d61625dSGraeme Russ /* Set second parameter to setup_gdt */ 1868d61625dSGraeme Russ movl %esp, %edx 1878d61625dSGraeme Russ 1888d61625dSGraeme Russ /* Setup global descriptor table so gd->xyz works */ 1898d61625dSGraeme Russ call setup_gdt 1908d61625dSGraeme Russ 191f48dd6fcSGraeme Russ /* Re-enter U-Boot by calling board_init_f_r */ 192f48dd6fcSGraeme Russ call board_init_f_r 193fea25720SGraeme Russ 1942f0e0cd2SGraeme Russdie: 1952f0e0cd2SGraeme Russ hlt 196fea25720SGraeme Russ jmp die 197fea25720SGraeme Russ hlt 198fea25720SGraeme Russ 199fea25720SGraeme Russblank_idt_ptr: 200fea25720SGraeme Russ .word 0 /* limit */ 201fea25720SGraeme Russ .long 0 /* base */ 202a206cc23SGraeme Russ 203a206cc23SGraeme Russ .p2align 2 /* force 4-byte alignment */ 204a206cc23SGraeme Russ 205a206cc23SGraeme Russmultiboot_header: 206a206cc23SGraeme Russ /* magic */ 207a206cc23SGraeme Russ .long 0x1BADB002 208a206cc23SGraeme Russ /* flags */ 209a206cc23SGraeme Russ .long (1 << 16) 210a206cc23SGraeme Russ /* checksum */ 211a206cc23SGraeme Russ .long -0x1BADB002 - (1 << 16) 212a206cc23SGraeme Russ /* header addr */ 213a206cc23SGraeme Russ .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE 214a206cc23SGraeme Russ /* load addr */ 215a206cc23SGraeme Russ .long CONFIG_SYS_TEXT_BASE 216a206cc23SGraeme Russ /* load end addr */ 217a206cc23SGraeme Russ .long 0 218a206cc23SGraeme Russ /* bss end addr */ 219a206cc23SGraeme Russ .long 0 220a206cc23SGraeme Russ /* entry addr */ 221a206cc23SGraeme Russ .long CONFIG_SYS_TEXT_BASE 222