Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Praveen hodagatta pranesh | b66757f | 2018-10-23 02:43:05 +0800 | [diff] [blame] | 4 | * Copyright (C) 2018 Intel Corp. |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <device/pci_def.h> |
| 18 | #include <cpu/x86/mtrr.h> |
| 19 | #include <cpu/x86/cache.h> |
| 20 | #include <cpu/x86/cr.h> |
| 21 | #include <cpu/x86/post_code.h> |
| 22 | |
Arthur Heymans | 0eb9c57 | 2019-01-05 18:21:47 +0100 | [diff] [blame^] | 23 | #define CBFS_FILE_MAGIC 0 |
| 24 | #define CBFS_FILE_LEN (CBFS_FILE_MAGIC + 8) |
| 25 | #define CBFS_FILE_TYPE (CBFS_FILE_LEN + 4) |
| 26 | #define CBFS_FILE_CHECKSUM (CBFS_FILE_TYPE + 4) |
| 27 | #define CBFS_FILE_OFFSET (CBFS_FILE_CHECKSUM + 4) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 28 | |
| 29 | .extern temp_ram_init_params |
| 30 | |
| 31 | .global bootblock_pre_c_entry |
| 32 | bootblock_pre_c_entry: |
| 33 | |
| 34 | .global cache_as_ram |
| 35 | cache_as_ram: |
Praveen hodagatta pranesh | b66757f | 2018-10-23 02:43:05 +0800 | [diff] [blame] | 36 | post_code(0x21) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 37 | |
| 38 | /* find fsp in cbfs */ |
| 39 | lea fsp_name, %esi |
| 40 | mov $1f, %esp |
| 41 | jmp walkcbfs_asm |
| 42 | 1: |
| 43 | cmp $0, %eax |
| 44 | jz .halt_forever |
| 45 | mov CBFS_FILE_OFFSET(%eax), %ebx |
| 46 | bswap %ebx |
| 47 | add %eax, %ebx |
Praveen hodagatta pranesh | b66757f | 2018-10-23 02:43:05 +0800 | [diff] [blame] | 48 | add $0x94, %ebx |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * save mm2 into ebp, because TempRamInit API doesn't preserve |
| 52 | * mm2 register |
| 53 | */ |
| 54 | movd %mm2, %ebp |
| 55 | |
| 56 | /* |
| 57 | * ebx = FSP INFO HEADER |
| 58 | * Calculate entry into FSP |
| 59 | */ |
| 60 | movl 0x30(%ebx), %eax /* Load TempRamInitEntryOffset */ |
| 61 | addl 0x1c(%ebx), %eax /* add the FSP ImageBase */ |
| 62 | |
| 63 | /* |
| 64 | * Pass early init variables on a fake stack (no memory yet) |
| 65 | * as well as the return location |
| 66 | */ |
| 67 | leal CAR_init_stack, %esp |
| 68 | |
| 69 | /* call FSP binary to setup temporary stack */ |
| 70 | jmp *%eax |
| 71 | |
| 72 | /* |
| 73 | * If the TempRamInit API is successful, then when returning, the ECX and |
| 74 | * EDX registers will point to the temporary but writeable memory range |
| 75 | * available to the bootloader where ECX is the start and EDX is the end of |
Praveen hodagatta pranesh | b66757f | 2018-10-23 02:43:05 +0800 | [diff] [blame] | 76 | * the range i.e. [ECX,EDX). See FSP Integration Guide for more information. |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 77 | * |
| 78 | * Return Values: |
| 79 | * EAX | Return Status |
| 80 | * ECX | Temporary Memory Start |
| 81 | * EDX | Temporary Memory End |
| 82 | * EBX, EDI, ESI, EBP, MM0, MM1 | Preserved Through API Call |
| 83 | */ |
| 84 | |
| 85 | CAR_init_done: |
| 86 | cmp $0, %eax |
| 87 | jnz .halt_forever |
| 88 | |
Praveen hodagatta pranesh | b66757f | 2018-10-23 02:43:05 +0800 | [diff] [blame] | 89 | /* Setup bootblock stack */ |
| 90 | mov %edx, %esp |
| 91 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 92 | /* clear CAR_GLOBAL area as it is not shared */ |
| 93 | cld |
Praveen hodagatta pranesh | b66757f | 2018-10-23 02:43:05 +0800 | [diff] [blame] | 94 | xor %eax, %eax |
| 95 | movl $(_car_global_end), %ecx |
| 96 | movl $(_car_global_start), %edi |
| 97 | sub %edi, %ecx |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 98 | shrl $2, %ecx |
Praveen hodagatta pranesh | b66757f | 2018-10-23 02:43:05 +0800 | [diff] [blame] | 99 | rep stosl |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 100 | |
| 101 | /* Restore the timestamp from bootblock_crt0.S (ebp:mm1) */ |
| 102 | push %ebp |
Praveen hodagatta pranesh | b66757f | 2018-10-23 02:43:05 +0800 | [diff] [blame] | 103 | movd %mm1, %eax |
| 104 | push %eax |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 105 | |
| 106 | /* We can call into C functions now */ |
| 107 | call bootblock_c_entry |
| 108 | |
| 109 | /* Never reached */ |
| 110 | |
| 111 | .halt_forever: |
| 112 | post_code(POST_DEAD_CODE) |
| 113 | hlt |
| 114 | jmp .halt_forever |
| 115 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 116 | CAR_init_stack: |
| 117 | .long CAR_init_done |
| 118 | .long temp_ram_init_params |
| 119 | |
| 120 | fsp_name: |
Praveen hodagatta pranesh | b66757f | 2018-10-23 02:43:05 +0800 | [diff] [blame] | 121 | .string "fspt.bin" |