SimpleKernel 1.17.0
Loading...
Searching...
No Matches
main.cpp File Reference
#include <MPMCQueue.hpp>
#include <cerrno>
#include <cstdint>
#include <new>
#include "arch.h"
#include "basic_info.hpp"
#include "expected.hpp"
#include "interrupt.h"
#include "kernel.h"
#include "kernel_log.hpp"
#include "kstd_cstdio"
#include "kstd_cstring"
#include "kstd_libcxx.h"
#include "mutex.hpp"
#include "per_cpu.hpp"
#include "sk_stdlib.h"
#include "syscall.hpp"
#include "task_control_block.hpp"
#include "task_manager.hpp"
#include "virtual_memory.hpp"
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

auto _start (int argc, const char **argv) -> void
 负责 crtbegin 的工作
 
auto main (int argc, const char **argv) -> int
 内核入口
 

Function Documentation

◆ _start()

auto _start ( int  argc,
const char **  argv 
)

负责 crtbegin 的工作

Parameters
argcriscv64: 启动核 id
argv参数指针 riscv64: dtb 地址
Returns
uint32_t 正常返回 0

Definition at line 134 of file main.cpp.

134 {
135 if (argv != nullptr) {
136 CppInit();
137 main(argc, argv);
138 } else {
139 main_smp(argc, argv);
140 }
141
142 while (true) {
144 }
145}
auto CppInit() -> void
构造 c++ 全局对象
void Pause()
Definition cpu_io.h:20
void main()
Definition main.cpp:33

◆ main()

auto main ( int  argc,
const char **  argv 
) -> int

内核入口

Parameters
argc同 _start
argv同 _start
Returns
int 正常返回 0

Definition at line 147 of file main.cpp.

147 {
148 // 初始化当前核心的 per_cpu 数据
149 per_cpu::PerCpuArraySingleton::create();
151
152 // 架构相关初始化
153 ArchInit(argc, argv);
154 // 内存相关初始化
155 MemoryInit();
156 // 中断相关初始化
157 InterruptInit(argc, argv);
158 // 设备管理器初始化
159 DeviceInit();
160 // 文件系统初始化
162 // 初始化任务管理器 (设置主线程)
163 TaskManagerSingleton::create();
164 TaskManagerSingleton::instance().InitCurrentCore();
165
166 TimerInit();
167
168 // 唤醒其余 core
170
171 DumpStack();
172
173 klog::Info("Hello SimpleKernel");
174
175 klog::Info("Initializing test tasks...");
176
177 // 为主核心创建测试任务
178 create_test_tasks();
179
180 klog::Info("Main: Starting scheduler...");
181
182 // 启动调度器,不再返回
183 TaskManagerSingleton::instance().Schedule();
184
185 // UNREACHABLE: Schedule() 不应返回
186 __builtin_unreachable();
187}
auto WakeUpOtherCores() -> void
唤醒其余 core
Definition arch_main.cpp:68
auto ArchInit(int argc, const char **argv) -> void
体系结构相关初始化
Definition arch_main.cpp:48
auto DumpStack() -> void
打印调用栈
Definition backtrace.cpp:34
auto InterruptInit(int, const char **) -> void
体系结构相关中断初始化
auto TimerInit() -> void
初始化定时器
Definition timer.cpp:47
auto DeviceInit() -> void
设备子系统初始化入口
Definition device.cpp:28
auto FileSystemInit() -> void
文件系统子系统初始化入口
auto MemoryInit() -> void
内存子系统初始化
Definition memory.cpp:71
auto GetCurrentCoreId() -> size_t
Definition cpu_io.h:26
auto Info(etl::format_string< Args... > fmt, Args &&... args) -> void
以 INFO 级别记录日志
static __always_inline auto GetCurrentCore() -> PerCpu &
获取当前核心的 PerCpu 数据
Definition per_cpu.hpp:55
每个 CPU 核心的局部数据
Definition per_cpu.hpp:23