SimpleKernel 1.17.0
Loading...
Searching...
No Matches
main.cpp File Reference
#include <atomic>
#include <cstdint>
#include <new>
#include "arch.h"
#include "basic_info.hpp"
#include "kernel.h"
#include "kernel_log.hpp"
#include "kstd_cstdio"
#include "kstd_libcxx.h"
#include "kstd_memory"
#include "per_cpu.hpp"
#include "spinlock.hpp"
#include "syscall.hpp"
#include "system_test.h"
#include "task_control_block.hpp"
#include "task_manager.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 237 of file main.cpp.

237 {
238 if (argv != nullptr) {
239 CppInit();
240 main(argc, argv);
241 } else {
242 main_smp(argc, argv);
243 }
244
245 while (true) {
247 }
248}
auto CppInit() -> void
构造 c++ 全局对象
void Pause()
Definition cpu_io.h:20
void main()
Definition main.cpp:33
Here is the call graph for this function:

◆ main()

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

内核入口

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

Definition at line 250 of file main.cpp.

250 {
251 per_cpu::PerCpuArraySingleton::create();
253
254 ArchInit(argc, argv);
255 MemoryInit();
256 InterruptInit(argc, argv);
257 DeviceInit();
259
260 TaskManagerSingleton::create();
261 TaskManagerSingleton::instance().InitCurrentCore();
262
263 TimerInit();
264
266
267 DumpStack();
268
269 klog::Info("Hello SimpleKernel");
270
271 for (size_t i = 0; i < kTestCount; ++i) {
272 test_results[i].name = test_cases[i].name;
273 test_results[i].status = TestThreadStatus::kPending;
274 test_results[i].exit_code = -1;
275 test_results[i].pid = 0;
276 }
277
278 // Phase 1: SMP 测试同步运行(需要跨核屏障协调,必须在调度器启动前完成)
279 size_t expected_cores = BasicInfoSingleton::instance().core_count - 1;
280 klog::Info("[RUNNER] Waiting for {} secondary core(s) to initialize...",
281 expected_cores);
282 while (g_cores_ready.load(std::memory_order_acquire) < expected_cores) {
284 }
285 klog::Info("[RUNNER] All cores ready, starting SMP tests");
286
287 for (size_t i = 0; i < kTestCount; ++i) {
288 if (!test_cases[i].is_smp_test) {
289 continue;
290 }
291 auto& result = test_results[i];
292 result.status = TestThreadStatus::kRunning;
293
294 klog::Info("[SMP] Running: {}", test_cases[i].name);
295 bool smp_passed = test_cases[i].func();
296
297 result.exit_code = smp_passed ? 0 : 1;
298 result.status =
300
301 klog::Info("[SMP] Finished: {} — {}", test_cases[i].name,
302 smp_passed ? "PASS" : "FAIL");
303 }
304
305 auto runner = kstd::make_unique<TaskControlBlock>("test_runner", 10,
306 test_runner_entry, nullptr);
307 TaskManagerSingleton::instance().AddTask(std::move(runner));
308
309 TaskManagerSingleton::instance().Schedule();
310
311 __builtin_unreachable();
312}
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
@ kPassed
测试通过
@ kRunning
运行中
@ kPending
等待启动
@ kFailed
测试失败
Here is the call graph for this function: