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 | * |
| 19 | * $Workfile:: cache_as_ram.inc |
| 20 | * |
| 21 | * Description: cache_as_ram.inc - AGESA Module Entry Point for GCC complier |
| 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> |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * XMM map: |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | .code32 |
| 34 | .globl cache_as_ram_setup, disable_cache_as_ram, cache_as_ram_setup_out |
| 35 | |
| 36 | cache_as_ram_setup: |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 37 | |
Kyösti Mälkki | 1779d53 | 2016-11-23 21:29:26 +0200 | [diff] [blame^] | 38 | /* Preserve BIST. */ |
| 39 | movl %eax, %ebp |
| 40 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 41 | post_code(0xa0) |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 42 | |
| 43 | /* enable SSE2 128bit instructions */ |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 44 | /* Turn on OSFXSR [BIT9] and OSXMMEXCPT [BIT10] onto CR4 register */ |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 45 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 46 | movl %cr4, %eax |
| 47 | orl $(3<<9), %eax |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 48 | movl %eax, %cr4 |
| 49 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 50 | post_code(0xa1) |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 51 | |
Kyösti Mälkki | 1779d53 | 2016-11-23 21:29:26 +0200 | [diff] [blame^] | 52 | /* NOTE: %ebx, %ebp are preserved in AMD_ENABLE_STACK. */ |
Kyösti Mälkki | f6fe2f1 | 2016-11-21 11:26:48 +0200 | [diff] [blame] | 53 | AMD_ENABLE_STACK |
| 54 | |
Kyösti Mälkki | 26929bd | 2016-11-23 20:40:53 +0200 | [diff] [blame] | 55 | /* Align the stack. */ |
| 56 | and $0xFFFFFFF0, %esp |
| 57 | |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 58 | #ifdef __x86_64__ |
| 59 | /* switch to 64 bit long mode */ |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 60 | mov %esi, %ecx |
| 61 | add $0, %ecx # core number |
| 62 | xor %eax, %eax |
| 63 | lea (0x1000+0x23)(%ecx), %edi |
| 64 | mov %edi, (%ecx) |
| 65 | mov %eax, 4(%ecx) |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 66 | |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 67 | lea 0x1000(%ecx), %edi |
| 68 | movl $0x000000e3, 0x00(%edi) |
| 69 | movl %eax, 0x04(%edi) |
| 70 | movl $0x400000e3, 0x08(%edi) |
| 71 | movl %eax, 0x0c(%edi) |
| 72 | movl $0x800000e3, 0x10(%edi) |
| 73 | movl %eax, 0x14(%edi) |
| 74 | movl $0xc00000e3, 0x18(%edi) |
| 75 | movl %eax, 0x1c(%edi) |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 76 | |
Elyes HAOUAS | 585d1a0 | 2016-07-28 19:15:34 +0200 | [diff] [blame] | 77 | # load ROM based identity mapped page tables |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 78 | mov %ecx, %eax |
| 79 | mov %eax, %cr3 |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 80 | |
| 81 | # enable PAE |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 82 | mov %cr4, %eax |
| 83 | bts $5, %eax |
| 84 | mov %eax, %cr4 |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 85 | |
| 86 | # enable long mode |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 87 | mov $0xC0000080, %ecx |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 88 | rdmsr |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 89 | bts $8, %eax |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 90 | wrmsr |
| 91 | |
| 92 | # enable paging |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 93 | mov %cr0, %eax |
| 94 | bts $31, %eax |
| 95 | mov %eax, %cr0 |
Stefan Reinauer | 67b9430 | 2015-06-18 01:14:01 -0700 | [diff] [blame] | 96 | |
| 97 | # use call far to switch to 64-bit code segment |
Patrick Georgi | 4a30ab9 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 98 | ljmp $0x18, $1f |
| 99 | 1: |
Kyösti Mälkki | 13cf135 | 2016-11-21 07:37:13 +0200 | [diff] [blame] | 100 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 101 | #endif |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 102 | |
Kyösti Mälkki | 1779d53 | 2016-11-23 21:29:26 +0200 | [diff] [blame^] | 103 | /* Calling conventions preserve BIST in %ebp. */ |
Kyösti Mälkki | 13cf135 | 2016-11-21 07:37:13 +0200 | [diff] [blame] | 104 | |
Kyösti Mälkki | 1779d53 | 2016-11-23 21:29:26 +0200 | [diff] [blame^] | 105 | call early_all_cores |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 106 | |
Kyösti Mälkki | 26929bd | 2016-11-23 20:40:53 +0200 | [diff] [blame] | 107 | /* Must maintain 16-byte stack alignment here. */ |
| 108 | pushl $0x0 |
| 109 | pushl $0x0 |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 110 | pushl $0x0 |
Kyösti Mälkki | 1779d53 | 2016-11-23 21:29:26 +0200 | [diff] [blame^] | 111 | pushl %ebp |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 112 | call romstage_main |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 113 | |
| 114 | /* Should never see this postcode */ |
| 115 | post_code(0xaf) |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 116 | stop: |
| 117 | jmp stop |
| 118 | |
| 119 | disable_cache_as_ram: |
| 120 | /* Save return stack */ |
Bruce Griffith | 59c3a06 | 2013-08-12 01:53:13 -0600 | [diff] [blame] | 121 | movd 0(%esp), %xmm1 |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 122 | movd %esp, %xmm0 |
| 123 | |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 124 | /* Disable cache */ |
| 125 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 126 | orl $CR0_CacheDisable, %eax |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 127 | movl %eax, %cr0 |
| 128 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 129 | AMD_DISABLE_STACK |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 130 | |
Siyuan Wang | f3b86b3 | 2012-11-01 18:51:15 +0800 | [diff] [blame] | 131 | /* enable cache */ |
| 132 | movl %cr0, %eax |
| 133 | andl $0x9fffffff, %eax |
| 134 | movl %eax, %cr0 |
| 135 | xorl %eax, %eax |
| 136 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 137 | /* Restore the return stack */ |
Bruce Griffith | 59c3a06 | 2013-08-12 01:53:13 -0600 | [diff] [blame] | 138 | wbinvd |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 139 | movd %xmm0, %esp |
Bruce Griffith | 59c3a06 | 2013-08-12 01:53:13 -0600 | [diff] [blame] | 140 | movd %xmm1, (%esp) |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 141 | ret |
efdesign98 | 4b50834 | 2011-07-13 17:16:13 -0700 | [diff] [blame] | 142 | |
efdesign98 | 7c0c64e | 2011-06-20 19:56:06 -0700 | [diff] [blame] | 143 | cache_as_ram_setup_out: |