blob: 6edcd0a36697c338af725a9f8ca447660a4fa15e [file] [log] [blame]
Eric Biedermanfcd5ace2004-10-14 19:29:29 +00001#include <cpu/x86/mtrr.h>
2#include <cpu/x86/lapic_def.h>
Stefan Reinauer5f5436f2010-04-25 20:42:02 +00003
Stefan Reinauer82ecf4c2012-11-15 15:53:30 -08004#if CONFIG_SMP && CONFIG_MAX_CPUS > 1
Eric Biedermanfcd5ace2004-10-14 19:29:29 +00005 .text
Aaron Durbina146d582013-02-08 16:56:51 -06006 .globl _secondary_start, _secondary_start_end, _secondary_gdt_addr
Sven Schnelle51676b12012-07-29 19:18:03 +02007 .balign 4096
Eric Biedermanfcd5ace2004-10-14 19:29:29 +00008_secondary_start:
9 .code16
10 cli
11 xorl %eax, %eax
12 movl %eax, %cr3 /* Invalidate TLB*/
13
14 /* On hyper threaded cpus, invalidating the cache here is
15 * very very bad. Don't.
16 */
17
18 /* setup the data segment */
19 movw %cs, %ax
20 movw %ax, %ds
21
22 data32 lgdt gdtaddr - _secondary_start
23
24 movl %cr0, %eax
25 andl $0x7FFAFFD1, %eax /* PG,AM,WP,NE,TS,EM,MP = 0 */
26 orl $0x60000001, %eax /* CD, NW, PE = 1 */
27 movl %eax, %cr0
28
Kyösti Mälkki63539bb2012-07-05 06:31:15 +030029 ljmpl $0x10, $__ap_protected_start
30
Aaron Durbina146d582013-02-08 16:56:51 -060031 /* This will get filled in by C code. */
32_secondary_gdt_addr:
Kyösti Mälkki63539bb2012-07-05 06:31:15 +030033gdtaddr:
Aaron Durbina146d582013-02-08 16:56:51 -060034 .word 0 /* the table limit */
35 .long 0 /* we know the offset */
Kyösti Mälkki63539bb2012-07-05 06:31:15 +030036
37_secondary_start_end:
38
39ap_protected_start:
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000040 .code32
Kyösti Mälkki63539bb2012-07-05 06:31:15 +030041 lgdt gdtaddr
42 ljmpl $0x10, $__ap_protected_start
43
44__ap_protected_start:
45
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000046 movw $0x18, %ax
47 movw %ax, %ds
48 movw %ax, %es
49 movw %ax, %ss
50 movw %ax, %fs
51 movw %ax, %gs
52
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +000053 /* Load the Interrupt descriptor table */
54 lidt idtarg
55
Sven Schnelle51676b12012-07-29 19:18:03 +020056 /* Set the stack pointer, and flag that we are done */
57 xorl %eax, %eax
58 movl secondary_stack, %esp
Ronald G. Minnich8b930592012-06-05 14:41:27 -070059 movl secondary_cpu_index, %edi
60 pushl %edi
Sven Schnelle51676b12012-07-29 19:18:03 +020061 movl %eax, secondary_stack
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000062
63 call secondary_cpu_init
641: hlt
65 jmp 1b
66
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000067.code32
Stefan Reinauer82ecf4c2012-11-15 15:53:30 -080068#endif