| 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 | // 设置3号系统调用 |
| 85 | systemService.setSystemCall(3, (int)syscall_exit); |
| 86 | // 设置4号系统调用 |
| 87 | systemService.setSystemCall(4, (int)syscall_wait); |
| 88 | // 设置5号系统调用 |
| 89 | systemService.setSystemCall(5, (int)syscall_move_cursor); |
| 90 | |
| 91 | // 内存管理器 |
| 92 | memoryManager.initialize(); |
| 93 | |
| 94 | // 创建第一个线程 |
| 95 | int pid = programManager.executeThread(first_thread, nullptr, "first thread", 1); |
| 96 | if (pid == -1) |
| 97 | { |
| 98 | printf("can not execute thread\n"); |
| 99 | asm_halt(); |
| 100 | } |
| 101 | |
| 102 | ListItem *item = programManager.readyPrograms.front(); |
| 103 | PCB *firstThread = ListItem2PCB(item, tagInGeneralList); |
| 104 | firstThread->status = ProgramStatus::RUNNING; |
| 105 | programManager.readyPrograms.pop_front(); |
| 106 | programManager.running = firstThread; |
| 107 | asm_switch_thread(0, firstThread); |
| 108 | |
| 109 | asm_halt(); |
| 110 | } |
nothing calls this directly
no test coverage detected