MCPcopy Create free account
hub / github.com/YatSenOS/YatSenOS-Tutorial-Volume-1 / load_process

Function load_process

lab8/src/5/src/kernel/program.cpp:292–339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290}
291
292void load_process(const char *filename)
293{
294 interruptManager.disableInterrupt();
295
296 PCB *process = programManager.running;
297 ProcessStartStack *interruptStack =
298 (ProcessStartStack *)((int)process + PAGE_SIZE - sizeof(ProcessStartStack));
299
300 interruptStack->edi = 0;
301 interruptStack->esi = 0;
302 interruptStack->ebp = 0;
303 interruptStack->esp_dummy = 0;
304 interruptStack->ebx = 0;
305 interruptStack->edx = 0;
306 interruptStack->ecx = 0;
307 interruptStack->eax = 0;
308 interruptStack->gs = 0;
309
310 interruptStack->fs = programManager.USER_DATA_SELECTOR;
311 interruptStack->es = programManager.USER_DATA_SELECTOR;
312 interruptStack->ds = programManager.USER_DATA_SELECTOR;
313
314 interruptStack->eip = (int)filename;
315 interruptStack->cs = programManager.USER_CODE_SELECTOR; // 用户模式平坦模式
316 interruptStack->eflags = (0 << 12) | (1 << 9) | (1 << 1); // IOPL, IF = 1 开中断, MBS = 1 默认
317
318 interruptStack->esp = memoryManager.allocatePages(AddressPoolType::USER, 1);
319 if (interruptStack->esp == 0)
320 {
321 printf("can not build process!\n");
322 process->status = ProgramStatus::DEAD;
323 asm_halt();
324 }
325 interruptStack->esp += PAGE_SIZE;
326
327 // 设置进程返回地址
328 int *userStack = (int *)interruptStack->esp;
329 userStack -= 3;
330 userStack[0] = (int)exit;
331 userStack[1] = 0;
332 userStack[2] = 0;
333
334 interruptStack->esp = (int)userStack;
335
336 interruptStack->ss = programManager.USER_STACK_SELECTOR;
337
338 asm_start_process((int)interruptStack);
339}
340
341void ProgramManager::activateProgramPage(PCB *program)
342{

Callers

nothing calls this directly

Calls 3

printfFunction · 0.70
disableInterruptMethod · 0.45
allocatePagesMethod · 0.45

Tested by

no test coverage detected