1fea25720SGraeme Russ/* 2fe0c33a5SBin Meng * 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> 16d1cd0459SSimon 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> 20fe0c33a5SBin Meng#include <generated/asm-offsets.h> 21fea25720SGraeme Russ 22fea25720SGraeme Russ.section .text 23fea25720SGraeme Russ.code32 24fea25720SGraeme Russ.globl _start 25fea25720SGraeme Russ.type _start, @function 26fea25720SGraeme Russ.globl _x86boot_start 27fea25720SGraeme Russ_x86boot_start: 28fea25720SGraeme Russ /* 29fea25720SGraeme Russ * This is the fail safe 32-bit bootstrap entry point. The 30fea25720SGraeme Russ * following code is not executed from a cold-reset (actually, a 31fea25720SGraeme Russ * lot of it is, but from real-mode after cold reset. It is 32fea25720SGraeme Russ * repeated here to put the board into a state as close to cold 33fea25720SGraeme Russ * reset as necessary) 34fea25720SGraeme Russ */ 35fea25720SGraeme Russ cli 36fea25720SGraeme Russ cld 37fea25720SGraeme Russ 382f0e0cd2SGraeme Russ /* Turn off cache (this might require a 486-class CPU) */ 39fea25720SGraeme Russ movl %cr0, %eax 40fea25720SGraeme Russ orl $(X86_CR0_NW | X86_CR0_CD), %eax 41fea25720SGraeme Russ movl %eax, %cr0 42fea25720SGraeme Russ wbinvd 43fea25720SGraeme Russ 4491d82a29SGabe Black /* Tell 32-bit code it is being entered from an in-RAM copy */ 4591d82a29SGabe Black movw $GD_FLG_WARM_BOOT, %bx 4691d82a29SGabe Black jmp 1f 47fea25720SGraeme Russ_start: 4891d82a29SGabe Black /* 4991d82a29SGabe Black * This is the 32-bit cold-reset entry point. Initialize %bx to 0 5091d82a29SGabe Black * in case we're preceeded by some sort of boot stub. 5191d82a29SGabe Black */ 5291d82a29SGabe Black movw $GD_FLG_COLD_BOOT, %bx 5391d82a29SGabe Black1: 54f67cd51eSSimon Glass /* Save BIST */ 55f67cd51eSSimon Glass movl %eax, %ebp 56fea25720SGraeme Russ 57fea25720SGraeme Russ /* Load the segement registes to match the gdt loaded in start16.S */ 58109ad143SGraeme Russ movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax 59fea25720SGraeme Russ movw %ax, %fs 60fea25720SGraeme Russ movw %ax, %ds 61fea25720SGraeme Russ movw %ax, %gs 62fea25720SGraeme Russ movw %ax, %es 63fea25720SGraeme Russ movw %ax, %ss 64fea25720SGraeme Russ 6516263087SMike Williams /* Clear the interrupt vectors */ 66fea25720SGraeme Russ lidt blank_idt_ptr 67fea25720SGraeme Russ 68fea25720SGraeme Russ /* Early platform init (setup gpio, etc ) */ 69fea25720SGraeme Russ jmp early_board_init 70fea25720SGraeme Russ.globl early_board_init_ret 71fea25720SGraeme Russearly_board_init_ret: 72d1cd0459SSimon Glass post_code(POST_START) 73fea25720SGraeme Russ 74fea25720SGraeme Russ /* Initialise Cache-As-RAM */ 75fea25720SGraeme Russ jmp car_init 76fea25720SGraeme Russ.globl car_init_ret 77fea25720SGraeme Russcar_init_ret: 78*bceb9f0fSBin Meng#ifndef CONFIG_HAVE_FSP 79fea25720SGraeme Russ /* 80fea25720SGraeme Russ * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM, 81fea25720SGraeme Russ * or fully initialised SDRAM - we really don't care which) 82fea25720SGraeme Russ * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack 8365dd74a6SSimon Glass * and early malloc area. The MRC requires some space at the top. 8476f90f30SSimon Glass * 8576f90f30SSimon Glass * Stack grows down from top of CAR. We have: 8676f90f30SSimon Glass * 8776f90f30SSimon Glass * top-> CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE 8865dd74a6SSimon Glass * MRC area 8976f90f30SSimon Glass * global_data 9076f90f30SSimon Glass * x86 global descriptor table 9176f90f30SSimon Glass * early malloc area 9276f90f30SSimon Glass * stack 9376f90f30SSimon Glass * bottom-> CONFIG_SYS_CAR_ADDR 94fea25720SGraeme Russ */ 9565dd74a6SSimon Glass movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE - 4), %esp 9665dd74a6SSimon Glass#ifdef CONFIG_DCACHE_RAM_MRC_VAR_SIZE 9765dd74a6SSimon Glass subl $CONFIG_DCACHE_RAM_MRC_VAR_SIZE, %esp 9865dd74a6SSimon Glass#endif 99*bceb9f0fSBin Meng#else 100*bceb9f0fSBin Meng /* 101*bceb9f0fSBin Meng * When we get here after car_init, esp points to a temporary stack 102*bceb9f0fSBin Meng * and esi holds the HOB list address returned by the FSP. 103*bceb9f0fSBin Meng */ 104*bceb9f0fSBin Meng#endif 1058d61625dSGraeme Russ 1068d61625dSGraeme Russ /* Reserve space on stack for global data */ 1078d61625dSGraeme Russ subl $GENERATED_GBL_DATA_SIZE, %esp 1088d61625dSGraeme Russ 1098d61625dSGraeme Russ /* Align global data to 16-byte boundary */ 1108d61625dSGraeme Russ andl $0xfffffff0, %esp 111d1cd0459SSimon Glass post_code(POST_START_STACK) 1128d61625dSGraeme Russ 113fbd72824SSimon Glass /* Zero the global data since it won't happen later */ 114fbd72824SSimon Glass xorl %eax, %eax 115fbd72824SSimon Glass movl $GENERATED_GBL_DATA_SIZE, %ecx 116fbd72824SSimon Glass movl %esp, %edi 117fbd72824SSimon Glass rep stosb 118fbd72824SSimon Glass 119*bceb9f0fSBin Meng#ifdef CONFIG_HAVE_FSP 120*bceb9f0fSBin Meng /* Store HOB list */ 121*bceb9f0fSBin Meng movl %esp, %edx 122*bceb9f0fSBin Meng addl $GD_HOB_LIST, %edx 123*bceb9f0fSBin Meng movl %esi, (%edx) 124*bceb9f0fSBin Meng#endif 125*bceb9f0fSBin Meng 12676f90f30SSimon Glass /* Setup first parameter to setup_gdt, pointer to global_data */ 1278d61625dSGraeme Russ movl %esp, %eax 1288d61625dSGraeme Russ 1298d61625dSGraeme Russ /* Reserve space for global descriptor table */ 1308d61625dSGraeme Russ subl $X86_GDT_SIZE, %esp 1318d61625dSGraeme Russ 13276f90f30SSimon Glass /* Align temporary global descriptor table to 16-byte boundary */ 13376f90f30SSimon Glass andl $0xfffffff0, %esp 13476f90f30SSimon Glass movl %esp, %ecx 13576f90f30SSimon Glass 1365dbcaa21SSimon Glass#if defined(CONFIG_SYS_MALLOC_F_LEN) 1375dbcaa21SSimon Glass subl $CONFIG_SYS_MALLOC_F_LEN, %esp 1385dbcaa21SSimon Glass movl %eax, %edx 1395dbcaa21SSimon Glass addl $GD_MALLOC_BASE, %edx 1405dbcaa21SSimon Glass movl %esp, (%edx) 1415dbcaa21SSimon Glass#endif 142f67cd51eSSimon Glass /* Store BIST */ 143f67cd51eSSimon Glass movl %eax, %edx 144f67cd51eSSimon Glass addl $GD_BIST, %edx 145f67cd51eSSimon Glass movl %ebp, (%edx) 1468d61625dSGraeme Russ 1478d61625dSGraeme Russ /* Set second parameter to setup_gdt */ 14876f90f30SSimon Glass movl %ecx, %edx 1498d61625dSGraeme Russ 1508d61625dSGraeme Russ /* Setup global descriptor table so gd->xyz works */ 1518d61625dSGraeme Russ call setup_gdt 1529e6c572fSGraeme Russ 153fea25720SGraeme Russ /* Set parameter to board_init_f() to boot flags */ 154d1cd0459SSimon Glass post_code(POST_START_DONE) 155fea25720SGraeme Russ xorl %eax, %eax 156fea25720SGraeme Russ 157fea25720SGraeme Russ /* Enter, U-boot! */ 158fea25720SGraeme Russ call board_init_f 159fea25720SGraeme Russ 160fea25720SGraeme Russ /* indicate (lack of) progress */ 161fea25720SGraeme Russ movw $0x85, %ax 162fea25720SGraeme Russ jmp die 163fea25720SGraeme Russ 164f48dd6fcSGraeme Russ.globl board_init_f_r_trampoline 165f48dd6fcSGraeme Russ.type board_init_f_r_trampoline, @function 166f48dd6fcSGraeme Russboard_init_f_r_trampoline: 167fea25720SGraeme Russ /* 168fea25720SGraeme Russ * SDRAM has been initialised, U-Boot code has been copied into 169fea25720SGraeme Russ * RAM, BSS has been cleared and relocation adjustments have been 170fea25720SGraeme Russ * made. It is now time to jump into the in-RAM copy of U-Boot 171fea25720SGraeme Russ * 172f48dd6fcSGraeme Russ * %eax = Address of top of new stack 173fea25720SGraeme Russ */ 174fea25720SGraeme Russ 1758d61625dSGraeme Russ /* Stack grows down from top of SDRAM */ 176fea25720SGraeme Russ movl %eax, %esp 177fea25720SGraeme Russ 1788d61625dSGraeme Russ /* Reserve space on stack for global data */ 1798d61625dSGraeme Russ subl $GENERATED_GBL_DATA_SIZE, %esp 1808d61625dSGraeme Russ 1818d61625dSGraeme Russ /* Align global data to 16-byte boundary */ 1828d61625dSGraeme Russ andl $0xfffffff0, %esp 1838d61625dSGraeme Russ 1848d61625dSGraeme Russ /* Setup first parameter to memcpy (and setup_gdt) */ 1858d61625dSGraeme Russ movl %esp, %eax 1868d61625dSGraeme Russ 1878d61625dSGraeme Russ /* Setup second parameter to memcpy */ 1888d61625dSGraeme Russ fs movl 0, %edx 1898d61625dSGraeme Russ 1908d61625dSGraeme Russ /* Set third parameter to memcpy */ 1918d61625dSGraeme Russ movl $GENERATED_GBL_DATA_SIZE, %ecx 1928d61625dSGraeme Russ 1938d61625dSGraeme Russ /* Copy global data from CAR to SDRAM stack */ 1948d61625dSGraeme Russ call memcpy 1958d61625dSGraeme Russ 1968d61625dSGraeme Russ /* Reserve space for global descriptor table */ 1978d61625dSGraeme Russ subl $X86_GDT_SIZE, %esp 1988d61625dSGraeme Russ 1998d61625dSGraeme Russ /* Align global descriptor table to 16-byte boundary */ 2008d61625dSGraeme Russ andl $0xfffffff0, %esp 2018d61625dSGraeme Russ 2028d61625dSGraeme Russ /* Set second parameter to setup_gdt */ 2038d61625dSGraeme Russ movl %esp, %edx 2048d61625dSGraeme Russ 2058d61625dSGraeme Russ /* Setup global descriptor table so gd->xyz works */ 2068d61625dSGraeme Russ call setup_gdt 2078d61625dSGraeme Russ 208f48dd6fcSGraeme Russ /* Re-enter U-Boot by calling board_init_f_r */ 209f48dd6fcSGraeme Russ call board_init_f_r 210fea25720SGraeme Russ 2112f0e0cd2SGraeme Russdie: 2122f0e0cd2SGraeme Russ hlt 213fea25720SGraeme Russ jmp die 214fea25720SGraeme Russ hlt 215fea25720SGraeme Russ 216fea25720SGraeme Russblank_idt_ptr: 217fea25720SGraeme Russ .word 0 /* limit */ 218fea25720SGraeme Russ .long 0 /* base */ 219a206cc23SGraeme Russ 220a206cc23SGraeme Russ .p2align 2 /* force 4-byte alignment */ 221a206cc23SGraeme Russ 222a206cc23SGraeme Russmultiboot_header: 223a206cc23SGraeme Russ /* magic */ 224a206cc23SGraeme Russ .long 0x1BADB002 225a206cc23SGraeme Russ /* flags */ 226a206cc23SGraeme Russ .long (1 << 16) 227a206cc23SGraeme Russ /* checksum */ 228a206cc23SGraeme Russ .long -0x1BADB002 - (1 << 16) 229a206cc23SGraeme Russ /* header addr */ 230a206cc23SGraeme Russ .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE 231a206cc23SGraeme Russ /* load addr */ 232a206cc23SGraeme Russ .long CONFIG_SYS_TEXT_BASE 233a206cc23SGraeme Russ /* load end addr */ 234a206cc23SGraeme Russ .long 0 235a206cc23SGraeme Russ /* bss end addr */ 236a206cc23SGraeme Russ .long 0 237a206cc23SGraeme Russ /* entry addr */ 238a206cc23SGraeme Russ .long CONFIG_SYS_TEXT_BASE 239