summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/amd64/amd64/cpu.c22
-rw-r--r--sys/arch/amd64/amd64/cpu_mp.c28
-rw-r--r--sys/arch/amd64/amd64/machdep.c12
3 files changed, 17 insertions, 45 deletions
diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c
index d8617d8..e608535 100644
--- a/sys/arch/amd64/amd64/cpu.c
+++ b/sys/arch/amd64/amd64/cpu.c
@@ -33,28 +33,8 @@
__KERNEL_META("$Hyra$: cpu.c, Ian Marco Moffett, "
"AMD64 CPU abstraction module");
-/* XXX: Must be zero'd!! */
-static struct cpu_info bsp_info = {0};
-
-struct cpu_info *
-amd64_get_bsp(void)
-{
- return &bsp_info;
-}
-
-/*
- * TODO: Update this when adding SMP
- * support.
- */
struct cpu_info *
amd64_this_cpu(void)
{
- struct cpu_ctx *cctx;
-
- if (!mp_supported()) {
- return amd64_get_bsp();
- }
-
- cctx = (void *)amd64_read_gs_base();
- return cctx->ci;
+ return (void *)amd64_read_gs_base();
}
diff --git a/sys/arch/amd64/amd64/cpu_mp.c b/sys/arch/amd64/amd64/cpu_mp.c
index c382439..b00e34e 100644
--- a/sys/arch/amd64/amd64/cpu_mp.c
+++ b/sys/arch/amd64/amd64/cpu_mp.c
@@ -49,34 +49,19 @@ static volatile struct limine_smp_request g_smp_req = {
static bool is_mp_supported = false;
static void
-ap_create_cctx(struct cpu_info *ci)
-{
- struct cpu_ctx *cctx;
-
- cctx = dynalloc(sizeof(struct cpu_ctx));
- __assert(cctx != NULL);
-
- cctx->ci = ci;
-
- /* Set *our* %GS now... */
- wrmsr(IA32_KERNEL_GS_BASE, (uintptr_t)cctx);
-
- if (!is_mp_supported) {
- is_mp_supported = true;
- }
-}
-
-static void
ap_trampoline(struct limine_smp_info *si)
{
struct cpu_info *ci;
+ static struct spinlock lock = {0};
- ci = (void *)si->extra_argument;
+ spinlock_acquire(&lock);
+ ci = (void *)si->extra_argument;
pre_init();
- ap_create_cctx(ci);
processor_init();
+ spinlock_release(&lock);
+
sched_init_processor(ci);
/* Should not be reached */
@@ -112,9 +97,6 @@ ap_bootstrap(struct cpu_info *ci)
panic("System only has 1 core!\n");
}
- /* Create processor context */
- ap_create_cctx(ci);
-
KINFO("Bootstrapping %d cores...\n", cpu_init_counter);
for (size_t i = 0; i < resp->cpu_count; ++i) {
if (ci->id == cpus[i]->lapic_id) {
diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c
index 8e7adce..9795dbe 100644
--- a/sys/arch/amd64/amd64/machdep.c
+++ b/sys/arch/amd64/amd64/machdep.c
@@ -41,9 +41,12 @@
#include <machine/cpu.h>
#include <machine/uart.h>
#include <vm/vm.h>
+#include <vm/dynalloc.h>
#include <vm/physseg.h>
#include <firmware/acpi/acpi.h>
#include <sys/syslog.h>
+#include <assert.h>
+#include <string.h>
__MODULE_NAME("machdep");
__KERNEL_META("$Hyra$: machdep.c, Ian Marco Moffett, "
@@ -135,8 +138,15 @@ processor_init(void)
{
/* Indicates what doesn't need to be init anymore */
static uint8_t init_flags = 0;
+ struct cpu_info *cur_cpu;
- struct cpu_info *cur_cpu = this_cpu();
+ /* Create our cpu_info structure */
+ cur_cpu = dynalloc(sizeof(struct cpu_info));
+ __assert(cur_cpu != NULL);
+ memset(cur_cpu, 0, sizeof(struct cpu_info));
+
+ /* Set %GS to cpu_info */
+ amd64_write_gs_base((uintptr_t)cur_cpu);
CPU_INFO_LOCK(cur_cpu);
init_tss(cur_cpu);