| 31 | } |
| 32 | |
| 33 | extern "C" void setup_kernel() |
| 34 | { |
| 35 | |
| 36 | // 中断管理器 |
| 37 | interruptManager.initialize(); |
| 38 | interruptManager.enableTimeInterrupt(); |
| 39 | interruptManager.setTimeInterrupt((void *)asm_time_interrupt_handler); |
| 40 | |
| 41 | // 输出管理器 |
| 42 | stdio.initialize(); |
| 43 | |
| 44 | // 进程/线程管理器 |
| 45 | programManager.initialize(); |
| 46 | |
| 47 | // 内存管理器 |
| 48 | memoryManager.initialize(); |
| 49 | |
| 50 | // 初始化系统调用 |
| 51 | systemService.initialize(); |
| 52 | // 设置0号系统调用 |
| 53 | systemService.setSystemCall(0, (int)syscall_0); |
| 54 | |
| 55 | int ret; |
| 56 | |
| 57 | ret = asm_system_call(0); |
| 58 | printf("return value: %d\n", ret); |
| 59 | |
| 60 | ret = asm_system_call(0, 123); |
| 61 | printf("return value: %d\n", ret); |
| 62 | |
| 63 | ret = asm_system_call(0, 123, 324); |
| 64 | printf("return value: %d\n", ret); |
| 65 | |
| 66 | ret = asm_system_call(0, 123, 324, 9248); |
| 67 | printf("return value: %d\n", ret); |
| 68 | |
| 69 | ret = asm_system_call(0, 123, 324, 9248, 7); |
| 70 | printf("return value: %d\n", ret); |
| 71 | |
| 72 | ret = asm_system_call(0, 123, 324, 9248, 7, 123); |
| 73 | printf("return value: %d\n", ret); |
| 74 | |
| 75 | // 创建第一个线程 |
| 76 | int pid = programManager.executeThread(first_thread, nullptr, "first thread", 1); |
| 77 | if (pid == -1) |
| 78 | { |
| 79 | printf("can not execute thread\n"); |
| 80 | asm_halt(); |
| 81 | } |
| 82 | |
| 83 | ListItem *item = programManager.readyPrograms.front(); |
| 84 | PCB *firstThread = ListItem2PCB(item, tagInGeneralList); |
| 85 | firstThread->status = RUNNING; |
| 86 | programManager.readyPrograms.pop_front(); |
| 87 | programManager.running = firstThread; |
| 88 | asm_switch_thread(0, firstThread); |
| 89 | |
| 90 | asm_halt(); |
nothing calls this directly
no test coverage detected