22std::array<cpu_io::GdtrInfo::SegmentDescriptor, cpu_io::GdtrInfo::kMaxCount>
23 kSegmentDescriptors = {
25 cpu_io::GdtrInfo::SegmentDescriptor(),
27 cpu_io::GdtrInfo::SegmentDescriptor(
28 cpu_io::GdtrInfo::SegmentDescriptor::Type::kCodeExecuteRead,
29 cpu_io::GdtrInfo::SegmentDescriptor::S::kCodeData,
30 cpu_io::GdtrInfo::SegmentDescriptor::DPL::kRing0,
31 cpu_io::GdtrInfo::SegmentDescriptor::P::kPresent,
32 cpu_io::GdtrInfo::SegmentDescriptor::AVL::kNotAvailable,
33 cpu_io::GdtrInfo::SegmentDescriptor::L::k64Bit),
35 cpu_io::GdtrInfo::SegmentDescriptor(
36 cpu_io::GdtrInfo::SegmentDescriptor::Type::kDataReadWrite,
37 cpu_io::GdtrInfo::SegmentDescriptor::S::kCodeData,
38 cpu_io::GdtrInfo::SegmentDescriptor::DPL::kRing0,
39 cpu_io::GdtrInfo::SegmentDescriptor::P::kPresent,
40 cpu_io::GdtrInfo::SegmentDescriptor::AVL::kNotAvailable,
41 cpu_io::GdtrInfo::SegmentDescriptor::L::k64Bit),
43 cpu_io::GdtrInfo::SegmentDescriptor(
44 cpu_io::GdtrInfo::SegmentDescriptor::Type::kCodeExecuteRead,
45 cpu_io::GdtrInfo::SegmentDescriptor::S::kCodeData,
46 cpu_io::GdtrInfo::SegmentDescriptor::DPL::kRing3,
47 cpu_io::GdtrInfo::SegmentDescriptor::P::kPresent,
48 cpu_io::GdtrInfo::SegmentDescriptor::AVL::kNotAvailable,
49 cpu_io::GdtrInfo::SegmentDescriptor::L::k64Bit),
51 cpu_io::GdtrInfo::SegmentDescriptor(
52 cpu_io::GdtrInfo::SegmentDescriptor::Type::kDataReadWrite,
53 cpu_io::GdtrInfo::SegmentDescriptor::S::kCodeData,
54 cpu_io::GdtrInfo::SegmentDescriptor::DPL::kRing3,
55 cpu_io::GdtrInfo::SegmentDescriptor::P::kPresent,
56 cpu_io::GdtrInfo::SegmentDescriptor::AVL::kNotAvailable,
57 cpu_io::GdtrInfo::SegmentDescriptor::L::k64Bit),
60cpu_io::GdtrInfo::Gdtr gdtr{
61 .limit = (
sizeof(cpu_io::GdtrInfo::SegmentDescriptor) *
62 cpu_io::GdtrInfo::kMaxCount) -
64 .base = kSegmentDescriptors.data(),
68auto SetupGdtAndSegmentRegisters() ->
void {
70 cpu_io::Gdtr::Write(gdtr);
73 cpu_io::Ds::Write(
sizeof(cpu_io::GdtrInfo::SegmentDescriptor) *
74 cpu_io::GdtrInfo::kKernelDataIndex);
75 cpu_io::Es::Write(
sizeof(cpu_io::GdtrInfo::SegmentDescriptor) *
76 cpu_io::GdtrInfo::kKernelDataIndex);
77 cpu_io::Fs::Write(
sizeof(cpu_io::GdtrInfo::SegmentDescriptor) *
78 cpu_io::GdtrInfo::kKernelDataIndex);
79 cpu_io::Gs::Write(
sizeof(cpu_io::GdtrInfo::SegmentDescriptor) *
80 cpu_io::GdtrInfo::kKernelDataIndex);
81 cpu_io::Ss::Write(
sizeof(cpu_io::GdtrInfo::SegmentDescriptor) *
82 cpu_io::GdtrInfo::kKernelDataIndex);
84 cpu_io::Cs::Write(
sizeof(cpu_io::GdtrInfo::SegmentDescriptor) *
85 cpu_io::GdtrInfo::kKernelCodeIndex);
102 core_count = cpu_io::cpuid::GetLogicalProcessorCount();
106 BasicInfoSingleton::create(0,
nullptr);
109 KernelElfSingleton::create(BasicInfoSingleton::instance().elf_addr);
112 SetupGdtAndSegmentRegisters();
119 SetupGdtAndSegmentRegisters();
121 InterruptSingleton::instance().apic().InitCurrentCpuLocalApic().or_else(
127 return std::unexpected(err);
134 target_sipi_params->
cr3 = cpu_io::Cr3::Read();
136 InterruptSingleton::instance().apic().StartupAllAps(
144 void (*entry)(
void*),
void* arg, uint64_t stack_top)
164 (void)trap_context_ptr;
auto WakeUpOtherCores() -> void
唤醒其余 core
auto InitTaskContext(cpu_io::CalleeSavedContext *task_context, void(*entry)(void *), void *arg, uint64_t stack_top) -> void
初始化内核线程的任务上下文(重载1)
auto ArchInit(int argc, const char **argv) -> void
体系结构相关初始化
auto ArchInitSMP(int argc, const char **argv) -> void
从核的体系结构相关初始化
void * __executable_start[]
std::expected< T, Error > Expected
std::expected 别名模板
auto Err(etl::format_string< Args... > fmt, Args &&... args) -> void
以 ERROR 级别记录日志
auto Info(etl::format_string< Args... > fmt, Args &&... args) -> void
以 INFO 级别记录日志
constexpr uint64_t kDefaultAPBase
启动 APs 的默认地址
uint64_t physical_memory_addr
physical_memory 地址
uint64_t kernel_addr
kernel 地址
size_t physical_memory_size
physical_memory 大小
size_t kernel_size
kernel 大小
constexpr auto message() const -> const char *