| 82 | } |
| 83 | |
| 84 | extern "C" void setup_kernel() |
| 85 | { |
| 86 | |
| 87 | // 中断管理器 |
| 88 | interruptManager.initialize(); |
| 89 | interruptManager.enableTimeInterrupt(); |
| 90 | interruptManager.setTimeInterrupt((void *)asm_time_interrupt_handler); |
| 91 | |
| 92 | // 输出管理器 |
| 93 | stdio.initialize(); |
| 94 | |
| 95 | // 进程/线程管理器 |
| 96 | programManager.initialize(); |
| 97 | |
| 98 | // 初始化系统调用 |
| 99 | systemService.initialize(); |
| 100 | // 设置0号系统调用 |
| 101 | systemService.setSystemCall(0, (int)syscall_0); |
| 102 | // 设置1号系统调用 |
| 103 | systemService.setSystemCall(1, (int)syscall_write); |
| 104 | // 设置2号系统调用 |
| 105 | systemService.setSystemCall(2, (int)syscall_fork); |
| 106 | // 设置3号系统调用 |
| 107 | systemService.setSystemCall(3, (int)syscall_exit); |
| 108 | // 设置4号系统调用 |
| 109 | systemService.setSystemCall(4, (int)syscall_wait); |
| 110 | |
| 111 | // 内存管理器 |
| 112 | memoryManager.initialize(); |
| 113 | |
| 114 | // 创建第一个线程 |
| 115 | int pid = programManager.executeThread(first_thread, nullptr, "first thread", 1); |
| 116 | if (pid == -1) |
| 117 | { |
| 118 | printf("can not execute thread\n"); |
| 119 | asm_halt(); |
| 120 | } |
| 121 | |
| 122 | ListItem *item = programManager.readyPrograms.front(); |
| 123 | PCB *firstThread = ListItem2PCB(item, tagInGeneralList); |
| 124 | firstThread->status = ProgramStatus::RUNNING; |
| 125 | programManager.readyPrograms.pop_front(); |
| 126 | programManager.running = firstThread; |
| 127 | asm_switch_thread(0, firstThread); |
| 128 | |
| 129 | asm_halt(); |
| 130 | } |
nothing calls this directly
no test coverage detected