blob: 0c4c0d061c25722069f84b8946d4899ae22e74d6 [file] [log] [blame]
Martin Roth6add44b2017-02-09 17:51:20 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000014#include <cpu/x86/mtrr.h>
15#include <cpu/x86/lapic_def.h>
Stefan Reinauer5f5436f2010-04-25 20:42:02 +000016
Stefan Reinauer82ecf4c2012-11-15 15:53:30 -080017#if CONFIG_SMP && CONFIG_MAX_CPUS > 1
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000018 .text
Aaron Durbina146d582013-02-08 16:56:51 -060019 .globl _secondary_start, _secondary_start_end, _secondary_gdt_addr
Sven Schnelle51676b12012-07-29 19:18:03 +020020 .balign 4096
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000021_secondary_start:
22 .code16
23 cli
24 xorl %eax, %eax
25 movl %eax, %cr3 /* Invalidate TLB*/
26
27 /* On hyper threaded cpus, invalidating the cache here is
28 * very very bad. Don't.
29 */
30
31 /* setup the data segment */
32 movw %cs, %ax
33 movw %ax, %ds
34
35 data32 lgdt gdtaddr - _secondary_start
36
37 movl %cr0, %eax
38 andl $0x7FFAFFD1, %eax /* PG,AM,WP,NE,TS,EM,MP = 0 */
39 orl $0x60000001, %eax /* CD, NW, PE = 1 */
40 movl %eax, %cr0
41
Kyösti Mälkki63539bb2012-07-05 06:31:15 +030042 ljmpl $0x10, $__ap_protected_start
43
Aaron Durbina146d582013-02-08 16:56:51 -060044 /* This will get filled in by C code. */
45_secondary_gdt_addr:
Kyösti Mälkki63539bb2012-07-05 06:31:15 +030046gdtaddr:
Aaron Durbina146d582013-02-08 16:56:51 -060047 .word 0 /* the table limit */
48 .long 0 /* we know the offset */
Kyösti Mälkki63539bb2012-07-05 06:31:15 +030049
50_secondary_start_end:
51
52ap_protected_start:
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000053 .code32
Kyösti Mälkki63539bb2012-07-05 06:31:15 +030054 lgdt gdtaddr
55 ljmpl $0x10, $__ap_protected_start
56
57__ap_protected_start:
58
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000059 movw $0x18, %ax
60 movw %ax, %ds
61 movw %ax, %es
62 movw %ax, %ss
63 movw %ax, %fs
64 movw %ax, %gs
65
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +000066 /* Load the Interrupt descriptor table */
67 lidt idtarg
68
Sven Schnelle51676b12012-07-29 19:18:03 +020069 /* Set the stack pointer, and flag that we are done */
70 xorl %eax, %eax
71 movl secondary_stack, %esp
Ronald G. Minnich8b930592012-06-05 14:41:27 -070072 movl secondary_cpu_index, %edi
73 pushl %edi
Sven Schnelle51676b12012-07-29 19:18:03 +020074 movl %eax, secondary_stack
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000075
76 call secondary_cpu_init
771: hlt
78 jmp 1b
79
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000080.code32
Stefan Reinauer82ecf4c2012-11-15 15:53:30 -080081#endif