📄 markfile
字号:
00537 _copr_not_available:00538 push 0 ! padding for error code 00539 push COPROC_NOT_VECTOR00540 jmp trap00541 00542 _double_fault:00543 push DOUBLE_FAULT_VECTOR00544 jmp trap00545 00546 _copr_seg_overrun:00547 push 0 ! padding for error code 00548 push COPROC_SEG_VECTOR00549 jmp trap00550 00551 _inval_tss:00552 push INVAL_TSS_VECTOR00553 jmp trap00554 00555 _segment_not_present:00556 push SEG_NOT_VECTOR00557 jmp trap00558 00559 _stack_exception:00560 push STACK_FAULT_VECTOR00561 jmp trap00562 00563 _general_protection:00564 push PROTECTION_VECTOR00565 jmp trap00566 00567 _page_fault:00568 push PAGE_FAULT_VECTOR00569 jmp trap00570 00571 _copr_error:00572 push 0 ! padding for error code 00573 push COPROC_ERR_VECTOR00574 jmp trap00575 00576 !*===========================================================================*00577 !* system call *00578 !*===========================================================================*00579 ! It shares the same interface with exception00580 00581 _s_call:00582 push 000583 push SYS386_VECTOR00584 jmp trap00585 00586 !*===========================================================================*00587 !* trap *00588 !*===========================================================================*00589 ! Called from all exceptions, no matter it has pushed an error code or not.00590 ! Remember to pop the error code from stack before execute iretd instruction00591 ! because iretd won't pop it.00592 00593 .align 1600594 trap:00595 cld ! set direction flag to a know value 00596 pushad ! save general registers 00597 push ds ! save ds 00598 push es ! save es 00599 push fs ! save fs 00600 push gs ! save gs 00601 o16 mov ax, KERNEL_VDATA_SELECTOR 00602 mov ds, ax ! we don't touch ss, becasue it was00603 mov es, ax ! already setup by kernel TSS if the00604 mov fs, ax ! previous mode is user. If the previous00605 mov gs, ax ! mode is kernel, reload is trivial.00606 mov eax,esp ! use eax as a base pointer.00607 push esp ! esp points to common stack frame00608 push 60(eax) ! get cs pushed.00609 sti ! allow interrupts00610 test (esp), RING000611 je 1f ! if ring000612 call _trap ! C verion trap routine00613 add esp, 4*2 ! pop used C arguments00614 2: cli ! disable interrupts00615 cmpb (_runrun), 000616 je 2f00617 sti ! unlock00618 call _swtch00619 jmp 2b00620 2: pop gs ! return to user mode00621 pop fs00622 pop es00623 pop ds00624 popad00625 add esp, 4*2 ! pop padding space00626 iretd00627 1: call _trap ! C verion trap routine00628 add esp, 4*2 ! pop used C arguemts00629 cli ! disable interrupts00630 pop gs ! return to kernel mode00631 pop fs00632 pop es00633 pop ds00634 popad00635 add esp, 4*2 ! pop padding space00636 iretd00637 00638 !*===========================================================================*00639 !* savu *00640 !*===========================================================================*00641 ! PUBLIC void savu(reg_t *kenv);00642 ! Save the kernel mode environment into user PPDA, it is highly cooperated00643 ! with retu to switch the kernel process. 00644 00645 .align 1600646 _savu:00647 cli ! atomic operating, interrupt is not allowed00648 pop eax ! get return address00649 mov edx, (esp) ! fetch the retiring process u_kenv pointer00650 mov (edx), esp ! get esp saved00651 add edx, 400652 mov (edx), ebp ! get ebp saved00653 add edx, 400654 mov (edx), ebx ! get ebx saved00655 add edx, 400656 mov (edx), esi ! get esi saved00657 add edx, 400658 mov (edx), edi ! get edi saved00659 add edx, 400660 pushf00661 pop ecx00662 mov (edx), ecx ! get eflags saved00663 sti ! unlock00664 jmp (eax) ! go back00665 00666 !*===========================================================================*00667 !* retu *00668 !*===========================================================================*00669 ! PUBLIC void retu(phys_bytes usr_pagetab);00670 ! Restore the kernel mode environment from user PPDA, it is highly cooperated00671 ! with savu to switch the kernel process00672 00673 .align 1600674 _retu:00675 cli ! atomic operating, interrupt is not allowed00676 pop eax ! get return address00677 mov edx, (esp) ! fetch the arising process page table pointer00678 mov eax, (edx)00679 mov cr3, eax ! restore arising process page table00680 mov edx, (_usr_ppda_ptr)00681 add edx, 12 ! get the arising process u_kenv pointer00682 mov esp, (edx) ! restore esp00683 add edx, 400684 mov ebp, (edx) ! restore ebp00685 add edx, 400686 mov ebx, (edx) ! restore ebx00687 add edx, 400688 mov esi, (edx) ! restore esi00689 add edx, 400690 mov edi, (edx) ! restore edi00691 add edx, 400692 mov ecx, (edx) 00693 push ecx00694 popf ! restore eflags00695 sti ! unlock00696 jmp (eax) ! go back00697 00698 !*===========================================================================*00699 !* aretu *00700 !*===========================================================================*00701 ! PUBLIC void aretu();00702 ! Used to performance the local goto. Mainly used to abort system call.00703 00704 .align 1600705 _aretu:00706 cli ! atomic operating, interrupt is not allowed00707 pop eax ! get return address00708 mov edx, (esp) ! fetch the retiring process u_qenv pointer00709 mov esp, (edx) ! restore esp00710 add edx, 400711 mov ebp, (edx) ! restore ebp00712 add edx, 400713 mov ebx, (edx) ! restore ebx00714 add edx, 400715 mov esi, (edx) ! restore esi00716 add edx, 400717 mov edi, (edx) ! restore edi00718 add edx, 400719 mov ecx, (edx) 00720 push ecx00721 popf ! restore eflags00722 sti ! unlock00723 jmp (eax) ! go back00724 00725 !*===========================================================================*00726 !* idle *00727 !*===========================================================================*00728 ! PUBLIC void idle();00729 ! Used to consume the processor idle time if there's no process runnable, only00730 ! the hardware interrupt can make it back.00731 00732 .align 1600733 _idle:00734 sti ! To allow peripheral interrupt00735 hlt00736 ret00737 00738 !*===========================================================================*00739 !* gohome *00740 !*===========================================================================*00741 ! PUBLIC void gohome();00742 ! Called only by swtch() to return to arising process environment, it prevents00743 ! the esi, edi registers from being restored again blindly. The ACK compiler00744 ! use these registers as local register variables, it restore these registers00745 ! before discarding the local stack variables. eax can be used to hold the 00746 ! return value from subroutine, the value returned here has many subtle00747 ! implications. See the newproc comments.00748 00749 .align 1600750 _gohome:00751 mov eax, 100752 leave00753 ret00754 00755
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -