SMP - We boot APs
- kernel detects CPUs by searching ACPI tables for local apic nodes - each CPU has its own TSS that points to its own stack. All cpus boot on the same boot stack (in sequence) but switch to its private stack as soon as they can. - final booting code in main() placed in bsp_finish_booting() which is executed only after the BSP switches to its final stack - apic functions to send startup interrupts - assembler functions to handle CPU features not needed for single cpu mode like memory barries, HT detection etc. - new files kernel/smp.[ch], kernel/arch/i386/arch_smp.c and kernel/arch/i386/include/arch_smp.h - 16-bit trampoline code for the APs. It is executed by each AP after receiving startup IPIs it brings up the CPUs to 32bit mode and let them spin in an infinite loop so they don't do any damage. - implementation of kernel spinlock - CONFIG_SMP and CONFIG_MAX_CPUS set by the build system
This commit is contained in:
@@ -2,6 +2,12 @@
|
||||
#ifndef _I386_PROTO_H
|
||||
#define _I386_PROTO_H
|
||||
|
||||
#include <machine/vm.h>
|
||||
|
||||
#define K_STACK_SIZE I386_PAGE_SIZE
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/* Hardware interrupt handlers. */
|
||||
_PROTOTYPE( void hwint00, (void) );
|
||||
_PROTOTYPE( void hwint01, (void) );
|
||||
@@ -95,6 +101,8 @@ _PROTOTYPE( void frstor, (void *));
|
||||
_PROTOTYPE( unsigned short fnstsw, (void));
|
||||
_PROTOTYPE( void fnstcw, (unsigned short* cw));
|
||||
|
||||
_PROTOTYPE( void switch_k_stack, (void * esp, void (* continuation)(void)));
|
||||
|
||||
_PROTOTYPE(void __switch_address_space, (struct proc * p,
|
||||
struct proc ** __ptproc));
|
||||
#define switch_address_space(proc) \
|
||||
@@ -132,8 +140,7 @@ struct tss_s {
|
||||
/* u8_t iomap[0]; */
|
||||
};
|
||||
|
||||
EXTERN struct tss_s tss;
|
||||
|
||||
_PROTOTYPE( void prot_init, (void) );
|
||||
_PROTOTYPE( void idt_init, (void) );
|
||||
_PROTOTYPE( void init_dataseg, (struct segdesc_s *segdp, phys_bytes base,
|
||||
vir_bytes size, int privilege) );
|
||||
@@ -151,13 +158,32 @@ struct gate_table_s {
|
||||
unsigned char privilege;
|
||||
};
|
||||
|
||||
EXTERN struct gate_table_s gate_table_pic[];
|
||||
extern struct gate_table_s gate_table_pic[];
|
||||
|
||||
/* copies an array of vectors to the IDT. The last vector must be zero filled */
|
||||
_PROTOTYPE(void idt_copy_vectors, (struct gate_table_s * first));
|
||||
_PROTOTYPE(void idt_reload,(void));
|
||||
|
||||
EXTERN void * k_boot_stktop;
|
||||
EXTERN void * k_stacks_start;
|
||||
extern void * k_stacks;
|
||||
|
||||
#define get_k_stack_top(cpu) ((void *)(((char*)(k_stacks)) \
|
||||
+ 2 * ((cpu) + 1) * K_STACK_SIZE))
|
||||
|
||||
#ifndef __GNUC__
|
||||
/* call a function to read the stack fram pointer (%ebp) */
|
||||
_PROTOTYPE(reg_t read_ebp, (void));
|
||||
#define get_stack_frame(__X) ((reg_t)read_ebp())
|
||||
#else
|
||||
/* read %ebp directly */
|
||||
#define get_stack_frame(__X) ((reg_t)__builtin_frame_address(0))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* sets up TSS for a cpu and assigns kernel stack and cpu id
|
||||
*/
|
||||
_PROTOTYPE(void tss_init, (unsigned cpu, void * kernel_stack));
|
||||
|
||||
_PROTOTYPE( void int_gate, (unsigned vec_nr, vir_bytes offset,
|
||||
unsigned dpl_type) );
|
||||
@@ -193,4 +219,6 @@ _PROTOTYPE(int platform_tbl_ptr, (phys_bytes start,
|
||||
/* functions defined in architecture-independent kernel source. */
|
||||
#include "kernel/proto.h"
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
#endif
|
||||
|
||||
42
kernel/arch/i386/include/arch_smp.h
Normal file
42
kernel/arch/i386/include/arch_smp.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef __SMP_X86_H__
|
||||
#define __SMP_X86_H__
|
||||
|
||||
#include "arch_proto.h" /* K_STACK_SIZE */
|
||||
|
||||
#define MAX_NR_INTERRUPT_ENTRIES 128
|
||||
|
||||
#define SMP_SCHED_PROC 0xF0
|
||||
#define SMP_DEQUEUE_PROC 0xF1
|
||||
#define SMP_CPU_REBOOT 0xF2
|
||||
#define SMP_CPU_HALT 0xF3
|
||||
#define SMP_ERROR_INT 0xF4
|
||||
|
||||
/* currently only 2 interrupt priority levels are used */
|
||||
#define SPL0 0x0
|
||||
#define SPLHI 0xF
|
||||
|
||||
#define SMP_IPI_DEST 0
|
||||
#define SMP_IPI_SELF 1
|
||||
#define SMP_IPI_TO_ALL 2
|
||||
#define SMP_IPI_TO_ALL_BUT_SELF 3
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/* returns the current cpu id */
|
||||
#define cpuid (((u32_t *)(((u32_t)get_stack_frame() + (K_STACK_SIZE - 1)) \
|
||||
& ~(K_STACK_SIZE - 1)))[-1])
|
||||
/*
|
||||
* in case apic or smp is disabled in boot monitor, we need to finish single cpu
|
||||
* boot using the legacy PIC
|
||||
*/
|
||||
#define smp_single_cpu_fallback() do { \
|
||||
tss_init(0, get_k_stack_top(0)); \
|
||||
bsp_finish_booting(); \
|
||||
} while(0)
|
||||
|
||||
extern unsigned char cpuid2apicid[CONFIG_MAX_CPUS];
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* __SMP_X86_H__ */
|
||||
|
||||
@@ -22,8 +22,10 @@
|
||||
#define SS_INDEX 5 /* kernel SS (386: monitor SS at startup) */
|
||||
#define CS_INDEX 6 /* kernel CS */
|
||||
#define MON_CS_INDEX 7 /* temp for BIOS (386: monitor CS at startup) */
|
||||
#define TSS_INDEX 8 /* kernel TSS */
|
||||
#define FIRST_LDT_INDEX 9 /* rest of descriptors are LDT's */
|
||||
#define TSS_INDEX_FIRST 8 /* first kernel TSS */
|
||||
#define TSS_INDEX_BOOT TSS_INDEX_FIRST
|
||||
#define TSS_INDEX(cpu) (TSS_INDEX_FIRST + (cpu)) /* per cpu kernel tss */
|
||||
#define FIRST_LDT_INDEX TSS_INDEX(CONFIG_MAX_CPUS) /* rest of descriptors are LDT's */
|
||||
|
||||
/* Descriptor structure offsets. */
|
||||
#define DESC_BASE 2 /* to base_low */
|
||||
@@ -44,7 +46,8 @@
|
||||
#define SS_SELECTOR SS_INDEX * DESC_SIZE
|
||||
#define CS_SELECTOR CS_INDEX * DESC_SIZE
|
||||
#define MON_CS_SELECTOR MON_CS_INDEX * DESC_SIZE
|
||||
#define TSS_SELECTOR TSS_INDEX * DESC_SIZE
|
||||
#define TSS_SELECTOR(cpu) (TSS_INDEX(cpu) * DESC_SIZE)
|
||||
#define TSS_SELECTOR_BOOT (TSS_INDEX_BOOT * DESC_SIZE)
|
||||
|
||||
/* Privileges. */
|
||||
#define INTR_PRIVILEGE 0 /* kernel and interrupt handlers */
|
||||
@@ -156,4 +159,11 @@
|
||||
/* Poweroff 16-bit code address */
|
||||
#define BIOS_POWEROFF_ENTRY 0x1000
|
||||
|
||||
|
||||
/*
|
||||
* defines how many bytes are reserved at the top of the kernel stack for global
|
||||
* information like currently scheduled process or current cpu id
|
||||
*/
|
||||
#define X86_STACK_TOP_RESERVED (2 * sizeof(reg_t))
|
||||
|
||||
#endif /* _I386_ACONST_H */
|
||||
|
||||
Reference in New Issue
Block a user