| 60 | } |
| 61 | |
| 62 | extern "C" void setup_kernel() |
| 63 | { |
| 64 | |
| 65 | // 中断管理器 |
| 66 | interruptManager.initialize(); |
| 67 | interruptManager.enableTimeInterrupt(); |
| 68 | interruptManager.setTimeInterrupt((void *)asm_time_interrupt_handler); |
| 69 | |
| 70 | // 输出管理器 |
| 71 | stdio.initialize(); |
| 72 | |
| 73 | // 进程/线程管理器 |
| 74 | programManager.initialize(); |
| 75 | |
| 76 | // 初始化系统调用 |
| 77 | systemService.initialize(); |
| 78 | // 设置0号系统调用 |
| 79 | systemService.setSystemCall(0, (int)syscall_0); |
| 80 | // 设置1号系统调用 |
| 81 | systemService.setSystemCall(1, (int)syscall_write); |
| 82 | // 设置2号系统调用 |
| 83 | systemService.setSystemCall(2, (int)syscall_fork); |
| 84 | |
| 85 | // 内存管理器 |
| 86 | memoryManager.initialize(); |
| 87 | |
| 88 | // 创建第一个线程 |
| 89 | int pid = programManager.executeThread(first_thread, nullptr, "first thread", 1); |
| 90 | if (pid == -1) |
| 91 | { |
| 92 | printf("can not execute thread\n"); |
| 93 | asm_halt(); |
| 94 | } |
| 95 | |
| 96 | ListItem *item = programManager.readyPrograms.front(); |
| 97 | PCB *firstThread = ListItem2PCB(item, tagInGeneralList); |
| 98 | firstThread->status = ProgramStatus::RUNNING; |
| 99 | programManager.readyPrograms.pop_front(); |
| 100 | programManager.running = firstThread; |
| 101 | asm_switch_thread(0, firstThread); |
| 102 | |
| 103 | asm_halt(); |
| 104 | } |
nothing calls this directly
no test coverage detected