Martin Roth | 6add44b | 2017-02-09 17:51:20 -0800 | [diff] [blame] | 1 | /* |
| 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 Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 14 | #include <cpu/x86/mtrr.h> |
| 15 | #include <cpu/x86/lapic_def.h> |
Stefan Reinauer | 5f5436f | 2010-04-25 20:42:02 +0000 | [diff] [blame] | 16 | |
Stefan Reinauer | 82ecf4c | 2012-11-15 15:53:30 -0800 | [diff] [blame] | 17 | #if CONFIG_SMP && CONFIG_MAX_CPUS > 1 |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 18 | .text |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 19 | .globl _secondary_start, _secondary_start_end, _secondary_gdt_addr |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 20 | .balign 4096 |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 21 | _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älkki | 63539bb | 2012-07-05 06:31:15 +0300 | [diff] [blame] | 42 | ljmpl $0x10, $__ap_protected_start |
| 43 | |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 44 | /* This will get filled in by C code. */ |
| 45 | _secondary_gdt_addr: |
Kyösti Mälkki | 63539bb | 2012-07-05 06:31:15 +0300 | [diff] [blame] | 46 | gdtaddr: |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 47 | .word 0 /* the table limit */ |
| 48 | .long 0 /* we know the offset */ |
Kyösti Mälkki | 63539bb | 2012-07-05 06:31:15 +0300 | [diff] [blame] | 49 | |
| 50 | _secondary_start_end: |
| 51 | |
| 52 | ap_protected_start: |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 53 | .code32 |
Kyösti Mälkki | 63539bb | 2012-07-05 06:31:15 +0300 | [diff] [blame] | 54 | lgdt gdtaddr |
| 55 | ljmpl $0x10, $__ap_protected_start |
| 56 | |
| 57 | __ap_protected_start: |
| 58 | |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 59 | 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 Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 66 | /* Load the Interrupt descriptor table */ |
| 67 | lidt idtarg |
| 68 | |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 69 | /* Set the stack pointer, and flag that we are done */ |
| 70 | xorl %eax, %eax |
| 71 | movl secondary_stack, %esp |
Ronald G. Minnich | 8b93059 | 2012-06-05 14:41:27 -0700 | [diff] [blame] | 72 | movl secondary_cpu_index, %edi |
| 73 | pushl %edi |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 74 | movl %eax, secondary_stack |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 75 | |
| 76 | call secondary_cpu_init |
| 77 | 1: hlt |
| 78 | jmp 1b |
| 79 | |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 80 | .code32 |
Stefan Reinauer | 82ecf4c | 2012-11-15 15:53:30 -0800 | [diff] [blame] | 81 | #endif |