mirror of
https://github.com/johndoe6345789/MetalOS.git
synced 2026-04-30 16:45:43 +00:00
Add basic multicore/SMP support for 6-core/12-thread systems
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
29
kernel/include/kernel/apic.h
Normal file
29
kernel/include/kernel/apic.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef METALOS_KERNEL_APIC_H
|
||||
#define METALOS_KERNEL_APIC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// APIC register offsets
|
||||
#define APIC_REG_ID 0x020
|
||||
#define APIC_REG_VERSION 0x030
|
||||
#define APIC_REG_TPR 0x080
|
||||
#define APIC_REG_EOI 0x0B0
|
||||
#define APIC_REG_SPURIOUS 0x0F0
|
||||
#define APIC_REG_ICR_LOW 0x300
|
||||
#define APIC_REG_ICR_HIGH 0x310
|
||||
#define APIC_REG_LVT_TIMER 0x320
|
||||
#define APIC_REG_LVT_ERROR 0x370
|
||||
|
||||
// IPI types
|
||||
#define APIC_IPI_INIT 0x500
|
||||
#define APIC_IPI_STARTUP 0x600
|
||||
|
||||
// APIC functions
|
||||
bool apic_is_available(void);
|
||||
void apic_init(void);
|
||||
uint8_t apic_get_id(void);
|
||||
void apic_send_eoi(void);
|
||||
void apic_send_ipi(uint8_t dest_apic_id, uint8_t vector, uint32_t delivery_mode);
|
||||
|
||||
#endif // METALOS_KERNEL_APIC_H
|
||||
36
kernel/include/kernel/smp.h
Normal file
36
kernel/include/kernel/smp.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef METALOS_KERNEL_SMP_H
|
||||
#define METALOS_KERNEL_SMP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// Maximum number of CPUs we support
|
||||
#define MAX_CPUS 16
|
||||
|
||||
// Per-CPU data structure
|
||||
typedef struct {
|
||||
uint8_t cpu_id;
|
||||
uint8_t apic_id;
|
||||
bool online;
|
||||
uint64_t kernel_stack;
|
||||
} cpu_info_t;
|
||||
|
||||
// SMP initialization
|
||||
void smp_init(void);
|
||||
|
||||
// Get number of CPUs detected
|
||||
uint8_t smp_get_cpu_count(void);
|
||||
|
||||
// Get current CPU ID
|
||||
uint8_t smp_get_current_cpu(void);
|
||||
|
||||
// Check if SMP is enabled
|
||||
bool smp_is_enabled(void);
|
||||
|
||||
// Get CPU info
|
||||
cpu_info_t* smp_get_cpu_info(uint8_t cpu_id);
|
||||
|
||||
// Mark CPU as online (internal use by AP startup)
|
||||
void smp_cpu_online(uint8_t cpu_id);
|
||||
|
||||
#endif // METALOS_KERNEL_SMP_H
|
||||
27
kernel/include/kernel/spinlock.h
Normal file
27
kernel/include/kernel/spinlock.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef METALOS_KERNEL_SPINLOCK_H
|
||||
#define METALOS_KERNEL_SPINLOCK_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// Spinlock structure
|
||||
typedef struct {
|
||||
volatile uint32_t lock;
|
||||
} spinlock_t;
|
||||
|
||||
// Initialize spinlock
|
||||
void spinlock_init(spinlock_t* lock);
|
||||
|
||||
// Acquire spinlock
|
||||
void spinlock_acquire(spinlock_t* lock);
|
||||
|
||||
// Try to acquire spinlock (non-blocking)
|
||||
bool spinlock_try_acquire(spinlock_t* lock);
|
||||
|
||||
// Release spinlock
|
||||
void spinlock_release(spinlock_t* lock);
|
||||
|
||||
// Check if locked
|
||||
bool spinlock_is_locked(spinlock_t* lock);
|
||||
|
||||
#endif // METALOS_KERNEL_SPINLOCK_H
|
||||
Reference in New Issue
Block a user