The Pedigree Project 0.1
x64/Multiprocessor.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include <config.h>
21
22#if MULTIPROCESSOR
23
24#include "pedigree/kernel/Spinlock.h"
25#include "pedigree/kernel/process/initialiseMultitasking.h"
26#include "pedigree/kernel/processor/NMFaultHandler.h"
27#include "pedigree/kernel/processor/Processor.h"
28
29#include "../x86_common/Multiprocessor.h"
30#include "InterruptManager.h"
31#include "SyscallManager.h"
32#include "gdt.h"
33#include "machine/mach_pc/LocalApic.h"
34#include "machine/mach_pc/Pc.h"
35
36void Multiprocessor::applicationProcessorStartup() {
37 // Enable Write-Protect on the AP early so we don't have any problems with
38 // the rest of the kernel.
39 asm volatile("mov %%cr0, %%rax; or $0x10000, %%rax; mov %%rax, %%cr0" ::: "rax");
40
41 // Initialise this processor's interrupt handling
43
44 // INIT/SIPI can leave an AP in xAPIC mode even when the BSP inherited x2APIC.
45 Pc::instance().getLocalApic().prepareApplicationProcessor();
46
47 // Signal the Bootstrap processor that this processor is started and the BSP
48 // can continue to boot up other processors.
49 m_ProcessorStarted = true;
50
51 // Wait until the GDT is initialised and the first 4MB identity mapping
52 // removed
53 m_ProcessorLock2.acquire(false, false);
54 m_ProcessorLock2.release();
55
56 // Initialise this processor's syscall handling
58
59 // Load the GDT
61
62 // Configure floating point.
64
65 // Invalidate the first 4MB identity mapping
67
68 // Initialise the machine-specific interface
69 Pc::instance().initialiseProcessor();
70
71 // We need to synchronize the -init section invalidation
73 Processor::invalidate(reinterpret_cast<void*>(0x200000));
74
75 // Start up the kernel process and idle thread for this processor.
76 initialiseMultitaskingPerProcessor();
77
78 // Call the per-processor code in main.cc
79 apMain();
80}
81
82#endif
static NMFaultHandler & instance()
bool initialiseProcessor()
static void invalidate(void *pAddress)
static void initialiseProcessor() INITIALISATION_ONLY
Definition gdt.cc:86
static void initialiseProcessor() INITIALISATION_ONLY
static void initialiseProcessor() INITIALISATION_ONLY
void apMain() NORETURN