push
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#ifndef PERCPU_H
|
||||
#define PERCPU_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "../include/smp/smp.h"
|
||||
|
||||
#define PERCPU_SECTION __attribute__((section(".percpu")))
|
||||
|
||||
typedef struct {
|
||||
uint64_t syscall_kernel_rsp;
|
||||
uint64_t syscall_user_rsp;
|
||||
uint32_t cpu_id;
|
||||
uint32_t _pad;
|
||||
void* current_task;
|
||||
uint64_t some_counter;
|
||||
bool need_resched;
|
||||
uint8_t _pad2[7];
|
||||
uint64_t user_saved_rbp;
|
||||
uint64_t user_saved_rbx;
|
||||
|
||||
uint64_t user_saved_r12;
|
||||
uint64_t user_saved_r13;
|
||||
uint64_t user_saved_r14;
|
||||
uint64_t user_saved_r15;
|
||||
uint64_t user_saved_r11;
|
||||
uint64_t user_saved_rip;
|
||||
uint8_t _pad3[8];
|
||||
void* deferred_free_task;
|
||||
uint64_t sched_stack_top;
|
||||
} __attribute__((aligned(64))) percpu_t;
|
||||
|
||||
_Static_assert(__builtin_offsetof(percpu_t, syscall_kernel_rsp) == 0, "percpu: kernel_rsp");
|
||||
_Static_assert(__builtin_offsetof(percpu_t, syscall_user_rsp) == 8, "percpu: user_rsp");
|
||||
_Static_assert(__builtin_offsetof(percpu_t, current_task) == 24, "percpu: current_task");
|
||||
_Static_assert(__builtin_offsetof(percpu_t, need_resched) == 40, "percpu: need_resched");
|
||||
_Static_assert(__builtin_offsetof(percpu_t, user_saved_rbp) == 48, "percpu: saved_rbp");
|
||||
_Static_assert(__builtin_offsetof(percpu_t, user_saved_rbx) == 56, "percpu: saved_rbx");
|
||||
_Static_assert(__builtin_offsetof(percpu_t, user_saved_r12) == 64, "percpu: saved_r12");
|
||||
_Static_assert(__builtin_offsetof(percpu_t, user_saved_r13) == 72, "percpu: saved_r13");
|
||||
_Static_assert(__builtin_offsetof(percpu_t, user_saved_r14) == 80, "percpu: saved_r14");
|
||||
_Static_assert(__builtin_offsetof(percpu_t, user_saved_r15) == 88, "percpu: saved_r15");
|
||||
_Static_assert(__builtin_offsetof(percpu_t, user_saved_r11) == 96, "percpu: saved_r11");
|
||||
_Static_assert(__builtin_offsetof(percpu_t, user_saved_rip) == 104, "percpu: saved_rip");
|
||||
|
||||
extern percpu_t percpu;
|
||||
extern percpu_t* percpu_regions[MAX_CPUS];
|
||||
extern bool g_has_fsgsbase;
|
||||
|
||||
percpu_t* get_percpu(void);
|
||||
percpu_t* get_percpu_mut(void);
|
||||
void init_percpu_regions(void);
|
||||
void set_percpu_base(percpu_t* base);
|
||||
#define current_cpu_id() (get_percpu()->cpu_id)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef SMP_H
|
||||
#define SMP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <limine.h>
|
||||
|
||||
#define AP_STACK_SIZE 16384
|
||||
#define MAX_CPUS 256
|
||||
|
||||
#define MAX_TLB_ADDRESSES 32
|
||||
|
||||
typedef struct {
|
||||
volatile bool pending;
|
||||
uintptr_t addresses[MAX_TLB_ADDRESSES];
|
||||
size_t count;
|
||||
} tlb_shootdown_t;
|
||||
|
||||
extern tlb_shootdown_t tlb_shootdown_queue[MAX_CPUS];
|
||||
typedef enum {
|
||||
CPU_UNINITIALIZED = 0,
|
||||
CPU_BOOTED,
|
||||
CPU_ONLINE,
|
||||
CPU_OFFLINE,
|
||||
CPU_FAULTED
|
||||
} cpu_state_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t lapic_id;
|
||||
uint32_t processor_id;
|
||||
uint32_t acpi_id;
|
||||
cpu_state_t state;
|
||||
bool is_bsp;
|
||||
uint64_t stack_top;
|
||||
uint32_t cpu_index;
|
||||
uint16_t tss_selector;
|
||||
} cpu_info_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t cpu_count;
|
||||
uint32_t online_count;
|
||||
uint32_t bsp_lapic_id;
|
||||
uint64_t lapic_base;
|
||||
cpu_info_t cpus[256];
|
||||
} smp_info_t;
|
||||
|
||||
void smp_init(struct limine_mp_response* mp_response);
|
||||
void smp_boot_aps(struct limine_mp_response* mp_response);
|
||||
smp_info_t* smp_get_info(void);
|
||||
cpu_info_t* smp_get_current_cpu(void);
|
||||
uint32_t smp_get_cpu_count(void);
|
||||
uint32_t smp_get_online_count(void);
|
||||
bool smp_is_bsp(void);
|
||||
void smp_print_info(void);
|
||||
void smp_print_info_fb(void);
|
||||
void smp_wait_for_ready(void);
|
||||
void ap_entry_point(struct limine_mp_info* cpu_info);
|
||||
void sched_notify_ready(void);
|
||||
#endif
|
||||
Reference in New Issue
Block a user