[SMP] Cpu initialization cleanup
This commit is contained in:
37
kernel/include/cpu.h
Normal file
37
kernel/include/cpu.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#define MAX_NUMCPU 64
|
||||
|
||||
#define GS_OFFSET_CPU 0
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
#include <stdint.h>
|
||||
#include <gdt.h>
|
||||
#include <process.h>
|
||||
#include <thread.h>
|
||||
|
||||
typedef struct cpu_t
|
||||
{
|
||||
uint64_t cpu;
|
||||
uint64_t id;
|
||||
uint64_t apic_id;
|
||||
uint64_t apic_ticks_per_us;
|
||||
uint64_t is_bsp;
|
||||
thread_t *current_thread;
|
||||
thread_t *last_thread;
|
||||
process_t *current_process;
|
||||
uint64_t gdt[5];
|
||||
struct gdtp_st gdt_p;
|
||||
thread_t *scheduler;
|
||||
}__attribute__((packed)) cpu_t;
|
||||
|
||||
extern cpu_t cpus[];
|
||||
extern unsigned int num_cpu;
|
||||
|
||||
void acpi_init();
|
||||
void cpu_add(uint64_t id, uint64_t apic);
|
||||
void cpu_init();
|
||||
cpu_t *get_cpu();
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ typedef struct process_st process_t;
|
||||
#include <stdint.h>
|
||||
#include <thread.h>
|
||||
#include <mem.h>
|
||||
#include <cpu.h>
|
||||
|
||||
typedef struct process_st
|
||||
{
|
||||
@@ -23,9 +24,8 @@ typedef struct process_st
|
||||
|
||||
#define process_alive(proc) ((proc)->state == PROC_STATE_READY || (proc)->state == PROC_STATE_RUNNING)
|
||||
|
||||
process_t *current_process;
|
||||
#define get_current_process() (current_process)
|
||||
#define set_current_process(proc) (current_process = (proc))
|
||||
#define get_current_process() (get_cpu()->current_process)
|
||||
#define set_current_process(proc) (get_cpu()->current_process = (proc))
|
||||
|
||||
process_t *process_spawn(process_t *parent);
|
||||
void process_attach(process_t *proc, thread_t *th);
|
||||
|
||||
@@ -4,6 +4,7 @@ typedef struct thread_st thread_t;
|
||||
#include <list.h>
|
||||
#include <process.h>
|
||||
#include <int.h>
|
||||
#include <cpu.h>
|
||||
|
||||
#define THREAD_STACK_SIZE 0x1000-sizeof(thread_t)
|
||||
|
||||
@@ -40,9 +41,8 @@ typedef struct thread_stack_st
|
||||
thread_t tcb;
|
||||
} thread_stack_t;
|
||||
|
||||
thread_t *current_thread;
|
||||
#define get_current_thread() (current_thread)
|
||||
#define set_current_thread(new) (current_thread = (new))
|
||||
#define get_current_thread() (get_cpu()->current_thread)
|
||||
#define set_current_thread(new) (get_cpu()->current_thread = (new))
|
||||
|
||||
thread_t *new_thread(void (*func)(void));
|
||||
void switch_thread(thread_t *old, thread_t *new);
|
||||
|
||||
Reference in New Issue
Block a user