efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Advanced Micro Devices, Inc. |
| 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; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 14 | */ |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 15 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 16 | /****************************************************************************** |
| 17 | * AMD Generic Encapsulated Software Architecture |
| 18 | * |
Kyösti Mälkki | 7076aa5 | 2017-09-02 16:20:15 +0300 | [diff] [blame] | 19 | * $Workfile:: cache_as_ram.S |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 20 | * |
Kyösti Mälkki | 7076aa5 | 2017-09-02 16:20:15 +0300 | [diff] [blame] | 21 | * Description: cache_as_ram.S - AGESA Module Entry Point for GCC complier |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 22 | * |
| 23 | ****************************************************************************** |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 24 | */ |
| 25 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 26 | #include "gcccar.inc" |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 27 | #include <cpu/x86/cache.h> |
Kyösti Mälkki | 7076aa5 | 2017-09-02 16:20:15 +0300 | [diff] [blame] | 28 | #include <cpu/x86/post_code.h> |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 29 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 30 | .code32 |
Kyösti Mälkki | 7076aa5 | 2017-09-02 16:20:15 +0300 | [diff] [blame] | 31 | .globl _cache_as_ram_setup, _cache_as_ram_setup_end |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 32 | |
Kyösti Mälkki | 7076aa5 | 2017-09-02 16:20:15 +0300 | [diff] [blame] | 33 | _cache_as_ram_setup: |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 34 | |
Kyösti Mälkki | 1779d53 | 2016-11-23 21:29:26 +0200 | [diff] [blame] | 35 | /* Preserve BIST. */ |
Kyösti Mälkki | fec6fa7 | 2017-07-12 16:30:47 +0300 | [diff] [blame] | 36 | movd %eax, %mm0 |
Kyösti Mälkki | 1779d53 | 2016-11-23 21:29:26 +0200 | [diff] [blame] | 37 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 38 | post_code(0xa0) |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 39 | |
| 40 | /* enable SSE2 128bit instructions */ |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 41 | /* Turn on OSFXSR [BIT9] and OSXMMEXCPT [BIT10] onto CR4 register */ |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 42 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 43 | movl %cr4, %eax |
Elyes HAOUAS | 168ef39 | 2017-06-27 22:54:42 +0200 | [diff] [blame] | 44 | orl $(3 << 9), %eax |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 45 | movl %eax, %cr4 |
| 46 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 47 | post_code(0xa1) |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 48 | |
Kyösti Mälkki | f6fe2f1 | 2016-11-21 11:26:48 +0200 | [diff] [blame] | 49 | AMD_ENABLE_STACK |
| 50 | |
Kyösti Mälkki | 26929bd | 2016-11-23 20:40:53 +0200 | [diff] [blame] | 51 | /* Align the stack. */ |
| 52 | and $0xFFFFFFF0, %esp |
| 53 | |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 54 | #ifdef __x86_64__ |
| 55 | /* switch to 64 bit long mode */ |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 56 | mov %esi, %ecx |
| 57 | add $0, %ecx # core number |
| 58 | xor %eax, %eax |
| 59 | lea (0x1000+0x23)(%ecx), %edi |
| 60 | mov %edi, (%ecx) |
| 61 | mov %eax, 4(%ecx) |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 62 | |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 63 | lea 0x1000(%ecx), %edi |
| 64 | movl $0x000000e3, 0x00(%edi) |
| 65 | movl %eax, 0x04(%edi) |
| 66 | movl $0x400000e3, 0x08(%edi) |
| 67 | movl %eax, 0x0c(%edi) |
| 68 | movl $0x800000e3, 0x10(%edi) |
| 69 | movl %eax, 0x14(%edi) |
| 70 | movl $0xc00000e3, 0x18(%edi) |
| 71 | movl %eax, 0x1c(%edi) |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 72 | |
Elyes HAOUAS | 585d1a0 | 2016-07-28 19:15:34 +0200 | [diff] [blame] | 73 | # load ROM based identity mapped page tables |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 74 | mov %ecx, %eax |
| 75 | mov %eax, %cr3 |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 76 | |
| 77 | # enable PAE |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 78 | mov %cr4, %eax |
| 79 | bts $5, %eax |
| 80 | mov %eax, %cr4 |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 81 | |
| 82 | # enable long mode |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 83 | mov $0xC0000080, %ecx |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 84 | rdmsr |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 85 | bts $8, %eax |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 86 | wrmsr |
| 87 | |
| 88 | # enable paging |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 89 | mov %cr0, %eax |
| 90 | bts $31, %eax |
| 91 | mov %eax, %cr0 |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 92 | |
| 93 | # use call far to switch to 64-bit code segment |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 94 | ljmp $0x18, $1f |
| 95 | 1: |
Kyösti Mälkki | 13cf135 | 2016-11-21 07:37:13 +0200 | [diff] [blame] | 96 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 97 | #endif |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 98 | |
Kyösti Mälkki | 1779d53 | 2016-11-23 21:29:26 +0200 | [diff] [blame] | 99 | call early_all_cores |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 100 | |
Kyösti Mälkki | 26929bd | 2016-11-23 20:40:53 +0200 | [diff] [blame] | 101 | /* Must maintain 16-byte stack alignment here. */ |
| 102 | pushl $0x0 |
| 103 | pushl $0x0 |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 104 | pushl $0x0 |
Kyösti Mälkki | fec6fa7 | 2017-07-12 16:30:47 +0300 | [diff] [blame] | 105 | movd %mm0, %eax /* bist */ |
| 106 | pushl %eax |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 107 | call romstage_main |
Kyösti Mälkki | fec6fa7 | 2017-07-12 16:30:47 +0300 | [diff] [blame] | 108 | movl %eax, %esp |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 109 | |
Kyösti Mälkki | fec6fa7 | 2017-07-12 16:30:47 +0300 | [diff] [blame] | 110 | /* Register %esp is new stacktop for remaining of romstage. |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 111 | * It is the only register preserved in AMD_DISABLE_STACK. |
| 112 | */ |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 113 | |
| 114 | disable_cache_as_ram: |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 115 | /* Disable cache */ |
| 116 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 117 | orl $CR0_CacheDisable, %eax |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 118 | movl %eax, %cr0 |
| 119 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 120 | AMD_DISABLE_STACK |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 121 | |
Siyuan Wang | f3b86b3 | 2012-11-01 18:51:15 +0800 | [diff] [blame] | 122 | /* enable cache */ |
| 123 | movl %cr0, %eax |
| 124 | andl $0x9fffffff, %eax |
| 125 | movl %eax, %cr0 |
Siyuan Wang | f3b86b3 | 2012-11-01 18:51:15 +0800 | [diff] [blame] | 126 | |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 127 | call romstage_after_car |
| 128 | |
| 129 | /* Should never see this postcode */ |
| 130 | post_code(0xaf) |
| 131 | stop: |
| 132 | jmp stop |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 133 | |
Kyösti Mälkki | 7076aa5 | 2017-09-02 16:20:15 +0300 | [diff] [blame] | 134 | _cache_as_ram_setup_end: |