smp: add base for SMP awareness
parent
6d0950501c
commit
38d9a9586d
@ -0,0 +1,50 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <arch/page.h>
|
||||
#include <arch/sched.h>
|
||||
|
||||
#include <gay/cdefs.h>
|
||||
#include <gay/config.h>
|
||||
#include <gay/types.h>
|
||||
|
||||
static inline int smp_cpuid(void)
|
||||
{
|
||||
#if CFG_SMP
|
||||
/*
|
||||
* The x86 has a dedicated CPUID instruction that can be used to query
|
||||
* pretty much anything except literally the cpu id. Therefore, we make
|
||||
* use of the fact that kernel stacks are always aligned to their size.
|
||||
* The cpu number is the topmost item on the stack; for cpu 0 this gets
|
||||
* pushed in the assembly routine in startup{32,64}.S and for all others
|
||||
* ... there is no implementation yet.
|
||||
*/
|
||||
u_register_t sp;
|
||||
|
||||
#ifdef __x86_64__
|
||||
__asm__ volatile("movq %%rsp, %0" : "=r"(sp));
|
||||
#else
|
||||
__asm__ volatile("movl %%esp, %0" : "=r"(sp));
|
||||
#endif
|
||||
|
||||
sp &= ~(KERN_STACK_SIZE - 1);
|
||||
return ((int *)sp)[KERN_STACK_SIZE / sizeof(int) - 1];
|
||||
#else /* !CFG_SMP */
|
||||
return 0;
|
||||
#endif /* !CFG_SMP */
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
@ -0,0 +1,41 @@
|
||||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ARCH_SCHED_H_
|
||||
#error "This file is not meant to be included directly, use <arch/page.h>"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief In-kernel context save for the x86.
|
||||
* This precise structure layout is hardcoded in assembly, so don't forget to
|
||||
* update `arch/x86/sys/switch.S` if you need to change it for whatever reason.
|
||||
*/
|
||||
struct x86_context {
|
||||
/**
|
||||
* The register itself is %esp, which points to the %eip that was pushed
|
||||
* by the function calling `arch_switch_to()` as per the x86 SysV ABI
|
||||
*/
|
||||
union {
|
||||
register_t esp;
|
||||
register_t *eip;
|
||||
};
|
||||
register_t esi;
|
||||
register_t edi;
|
||||
register_t ebx;
|
||||
register_t ebp;
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
Loading…
Reference in New Issue