Starter(BootLoader)是 ZerOS 内核的启动引导程序,负责管理模块依赖关系,按正确顺序异步加载所有内核模块。提供模块加载、依赖解析、内核自检等功能。
KernelLogger - 内核日志系统(用于日志输出)DependencyConfig - 依赖管理器(用于依赖管理)POOL - 全局对象池(用于对象管理)BootLoader 定义了完整的模块依赖关系图,确保模块按正确顺序加载:
const MODULE_DEPENDENCIES = {
// 第一层:基础枚举管理器
"../kernel/typePool/enumManager.js": [],
// 第三层:依赖 enumManager 的枚举
"../kernel/typePool/logLevel.js": ["../kernel/typePool/enumManager.js"],
"../kernel/typePool/addressType.js": ["../kernel/typePool/enumManager.js"],
"../kernel/typePool/fileType.js": ["../kernel/typePool/enumManager.js"],
// 第四层:文件系统模块
"../kernel/filesystem/fileFramework.js": ["../kernel/typePool/fileType.js"],
"../kernel/filesystem/disk.js": [],
"../kernel/filesystem/nodeTree.js": ["../kernel/typePool/fileType.js"],
// 第五层:内存管理模块
"../kernel/memory/memoryManager.js": ["../kernel/typePool/logLevel.js", ...],
// 第六层:进程管理模块
"../kernel/process/processManager.js": ["../kernel/memory/memoryManager.js", ...],
// ... 更多模块
};
BootLoader 的启动流程:
loadModules(dependencies)异步加载所有模块(按依赖顺序,支持并行加载)。
参数:
dependencies (Object): 依赖关系图返回值: Promise<void>
示例:
// BootLoader 内部使用,通常不需要直接调用
await loadModules(MODULE_DEPENDENCIES);
loadScript(src)异步加载单个脚本文件。
参数:
src (string): 脚本路径返回值: Promise<void>
示例:
// BootLoader 内部使用,通常不需要直接调用
await loadScript("../kernel/process/processManager.js");
topologicalSort(dependencies)拓扑排序:计算模块加载顺序。
参数:
dependencies (Object): 依赖关系图返回值: Array<string> - 排序后的模块列表
示例:
// BootLoader 内部使用,通常不需要直接调用
const sortedModules = topologicalSort(MODULE_DEPENDENCIES);
performKernelSelfCheck(progressCallback)执行内核自检。
参数:
progressCallback (Function): 进度回调函数 (step, message, percent) => void(可选)返回值: Promise<Object> - 自检结果
{
passed: number, // 通过的检查数
failed: number, // 失败的检查数
warnings: number, // 警告数
criticalErrors: number, // 严重错误数
totalChecks: number // 总检查数
}
示例:
const result = await performKernelSelfCheck((step, message, percent) => {
console.log(`[${percent}%] ${step}: ${message}`);
});
console.log(`自检结果: 通过 ${result.passed}, 失败 ${result.failed}, 警告 ${result.warnings}`);
if (result.criticalErrors > 0) {
console.error(`严重错误: ${result.criticalErrors}`);
}
内核自检包括以下项目:
核心模块检查
文件系统模块检查
内存管理模块检查
进程管理模块检查
GUI 管理模块检查
GUI 管理模块检查
驱动层检查
系统信息检查
// BootLoader 在 HTML 中自动启动
// 通常不需要手动调用
// 如果需要手动启动(不推荐)
if (typeof BootLoader !== 'undefined') {
await BootLoader.start();
}
// 在系统启动后执行自检
const result = await performKernelSelfCheck((step, message, percent) => {
console.log(`[${percent}%] ${step}: ${message}`);
});
if (result.criticalErrors > 0) {
console.error('内核自检发现严重错误,系统可能无法正常运行');
} else if (result.failed > 0) {
console.warn('内核自检发现一些问题,但系统可以继续运行');
} else {
console.log('内核自检通过,所有模块正常');
}
// 在 MODULE_DEPENDENCIES 中添加模块
const MODULE_DEPENDENCIES = {
// ... 现有模块
// 添加自定义模块
"../kernel/custom/myModule.js": [
"../kernel/process/processManager.js"
]
};
DependencyConfig.publishSignal())