SLIDE 30 Restoring registers
06681 _restart: 06682 06683 ! Restart the current process or the next process if it is set. 06684 06685 cmp (_next_ptr), 0 ! see if another process is scheduled 06686 jz 0f 06687 mov eax, (_next_ptr) 06688 mov (_proc_ptr), eax ! schedule new process 06689 mov (_next_ptr), 0 06690 0: mov esp, (_proc_ptr) ! will assume P_STACKBASE == 0 06691 lldt P_LDT_SEL(esp) ! enable process’ segment descriptors 06692 lea eax, P_STACKTOP(esp) ! arrange for next interrupt 06693 mov (_tss+TSS3_S_SP0), eax ! to save state in process table 06694 restart1: 06695 decb (_k_reenter) 06696
gs 06697
fs 06698
es 06699
ds 06700 popad 06701 add esp, 4 ! skip return adr
❭❙❪✿❫❍❴✿❵✮❴❜❛✿❝❂❛◆❞❩❵✮❴✿❡✮❴✿❵❄❵▼❛✻❢✮❣❩❞❍❤❄✐❍❥
06702 iretd ! continue process
02 – 58 Processes/2.6 Implementation in MINIX
System Calls
06648 .align 16 06649 _s_call: 06650 _p_s_call: 06651 cld ! set direction flag to a known value 06652 sub esp, 6*4 ! skip RETADR, eax, ecx, edx, ebx, est 06653 push ebp ! stack already points into proc table 06654 push esi 06655 push edi 06656
ds 06657
es 06658
fs 06659
gs 06660 mov dx, ss 06661 mov ds, dx 06662 mov es, dx 06663 incb (_k_reenter) 06664 mov esi, esp ! assumes P_STACKBASE == 0 06665 mov esp, k_stktop !
❭✻❝❑❪▼❛◆❞✷❦◆❫❂❞❍❤❘❧✮❴✿❵✿❢❍❴✮♠❂❝❑❞✮♥❍❦❑❧▼❥
06666 xor ebp, ebp ! for stacktrace 06667 ! end of inline save 06668 ! now set up parameters for sys_call() 06669 push ebx ! pointer to user message 06670 push eax ! src/dest 06671 push ecx ! SEND/RECEIVE/BOTH 06672 call _sys_call ! sys_call(function, src_dest, m_ptr) 06673 ! caller is now explicitly in proc_ptr 06674 mov AXREG(esi), eax ! sys_call MUST PRESERVE si 06675 06676 ! Fall into code to restart proc/task running.
Note: s call is called by a nonkernel process to in- voke a system service. This means switching from user to kernel mode. When call is finished, we con- tinue with restart().
02 – 59 Processes/2.6 Implementation in MINIX