2016-03-18 18:21:23 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; version 2 of
|
|
|
|
* the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cpu/x86/mtrr.h>
|
|
|
|
#include <cpu/x86/cr.h>
|
|
|
|
|
|
|
|
.section ".module_parameters", "aw", @progbits
|
|
|
|
/* stack_top indicates the stack to pull MTRR information from. */
|
2016-10-18 22:57:54 +02:00
|
|
|
.global post_car_stack_top
|
|
|
|
post_car_stack_top:
|
2016-03-18 18:21:23 +01:00
|
|
|
.long 0
|
|
|
|
.long 0
|
|
|
|
|
|
|
|
.text
|
|
|
|
.global _start
|
|
|
|
_start:
|
2017-06-23 18:14:58 +02:00
|
|
|
/* Assume stack alignment doesn't matter here as chipset_teardown_car
|
|
|
|
is expected to be implemented in assembly. */
|
|
|
|
|
2018-04-27 18:09:04 +02:00
|
|
|
/* Migrate GDT to this text segment */
|
|
|
|
call gdt_init
|
|
|
|
|
2019-10-23 17:02:50 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
mov %rdi, _cbmem_top_ptr
|
|
|
|
#else
|
|
|
|
/* The return argument is at 0(%esp), the calling argument at 4(%esp) */
|
|
|
|
movl 4(%esp), %eax
|
|
|
|
movl %eax, _cbmem_top_ptr
|
|
|
|
#endif
|
|
|
|
|
2016-03-18 18:21:23 +01:00
|
|
|
/* chipset_teardown_car() is expected to disable cache-as-ram. */
|
|
|
|
call chipset_teardown_car
|
|
|
|
|
|
|
|
/* Enable caching if not already enabled. */
|
|
|
|
mov %cr0, %eax
|
|
|
|
and $(~(CR0_CD | CR0_NW)), %eax
|
|
|
|
mov %eax, %cr0
|
|
|
|
|
|
|
|
/* Ensure cache is clean. */
|
|
|
|
invd
|
|
|
|
|
|
|
|
/* Set up new stack. */
|
2016-10-18 22:57:54 +02:00
|
|
|
mov post_car_stack_top, %esp
|
2016-03-18 18:21:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Honor variable MTRR information pushed on the stack with the
|
|
|
|
* following layout:
|
|
|
|
*
|
|
|
|
* Offset: Value
|
|
|
|
* ...
|
|
|
|
* 0x14: MTRR mask 0 63:32
|
|
|
|
* 0x10: MTRR mask 0 31:0
|
|
|
|
* 0x0c: MTRR base 0 63:32
|
|
|
|
* 0x08: MTRR base 0 31:0
|
|
|
|
* 0x04: Number of variable MTRRs to set
|
|
|
|
* 0x00: Number of variable MTRRs to clear
|
|
|
|
*/
|
|
|
|
|
2019-03-06 01:53:33 +01:00
|
|
|
#if CONFIG(SOC_SETS_MSRS)
|
2017-06-23 18:14:58 +02:00
|
|
|
|
|
|
|
mov %esp, %ebp
|
|
|
|
/* Need to align stack to 16 bytes at the call instruction. Therefore
|
|
|
|
account for the 1 push. */
|
|
|
|
andl $0xfffffff0, %esp
|
|
|
|
sub $12, %esp
|
|
|
|
push %ebp
|
2016-07-24 17:09:40 +02:00
|
|
|
call soc_set_mtrrs
|
2017-06-23 18:14:58 +02:00
|
|
|
/* Ignore fixing up %esp since we're setting it a new value. */
|
2016-07-24 17:09:40 +02:00
|
|
|
|
|
|
|
/* eax: new top_of_stack with setup_stack_and_mtrrs data removed */
|
|
|
|
movl %eax, %esp
|
2017-06-23 18:14:58 +02:00
|
|
|
/* Align stack to 16 bytes at call instruction. */
|
|
|
|
andl $0xfffffff0, %esp
|
2016-07-24 17:09:40 +02:00
|
|
|
call soc_enable_mtrrs
|
|
|
|
#else /* CONFIG_SOC_SETS_MSRS */
|
2016-03-18 18:21:23 +01:00
|
|
|
/* Clear variable MTRRs. */
|
|
|
|
pop %ebx /* Number to clear */
|
|
|
|
test %ebx, %ebx
|
|
|
|
jz 2f
|
|
|
|
xor %eax, %eax
|
|
|
|
xor %edx, %edx
|
|
|
|
mov $(MTRR_PHYS_BASE(0)), %ecx
|
|
|
|
1:
|
|
|
|
wrmsr
|
|
|
|
inc %ecx
|
|
|
|
wrmsr
|
|
|
|
inc %ecx
|
|
|
|
dec %ebx
|
|
|
|
jnz 1b
|
|
|
|
2:
|
|
|
|
|
|
|
|
/* Set Variable MTRRs based on stack contents. */
|
|
|
|
pop %ebx /* Number to set. */
|
|
|
|
test %ebx, %ebx
|
|
|
|
jz 2f
|
|
|
|
mov $(MTRR_PHYS_BASE(0)), %ecx
|
|
|
|
1:
|
|
|
|
/* Write MTRR base. */
|
|
|
|
pop %eax
|
|
|
|
pop %edx
|
|
|
|
wrmsr
|
|
|
|
inc %ecx
|
|
|
|
/* Write MTRR mask. */
|
|
|
|
pop %eax
|
|
|
|
pop %edx
|
|
|
|
wrmsr
|
|
|
|
inc %ecx
|
|
|
|
|
|
|
|
dec %ebx
|
|
|
|
jnz 1b
|
|
|
|
2:
|
|
|
|
|
|
|
|
/* Enable MTRR. */
|
|
|
|
mov $(MTRR_DEF_TYPE_MSR), %ecx
|
|
|
|
rdmsr
|
|
|
|
/* Make default type uncacheable. */
|
|
|
|
and $(~(MTRR_DEF_TYPE_MASK)), %eax
|
|
|
|
or $(MTRR_DEF_TYPE_EN), %eax
|
|
|
|
wrmsr
|
2016-07-24 17:09:40 +02:00
|
|
|
#endif /* CONFIG_SOC_SETS_MSRS */
|
2016-03-18 18:21:23 +01:00
|
|
|
|
2017-06-23 18:14:58 +02:00
|
|
|
/* Align stack to 16 bytes at call instruction. */
|
|
|
|
andl $0xfffffff0, %esp
|
2016-09-16 23:15:14 +02:00
|
|
|
/* Call into main for postcar. */
|
|
|
|
call main
|
2016-03-18 18:21:23 +01:00
|
|
|
/* Should never return. */
|
|
|
|
1:
|
|
|
|
jmp 1b
|