Linux 版 (精华区)

发信人: tdx (汤大虾), 信区: Linux
标  题: 操作系统讲稿(汤大虾转载)5
发信站: 紫 丁 香 (Sun Feb 27 18:45:33 2000) WWW-POST

2.5 软中断

PUBLIC int _syscall(who, syscallnr, msgptr)
int who;
int syscallnr;
register message *msgptr;
{
  int status;

  msgptr->m_type = syscallnr;
  status = _sendrec(who, msgptr);
  if (status != 0) {
/* 'sendrec' itself failed. */
/* XXX - strerror doesn't know all the codes */
msgptr->m_type = status;
  }
  if (msgptr->m_type < 0) {
errno = -msgptr->m_type;
return(-1);
  }
  return(msgptr->m_type);
}

! _send(), _receive(), _sendrec() all save ebp, but destroy eax and ecx.
.define __send, __receive, __sendrec
.sect .text
__send:
push ebp
mov ebp, esp
push ebx
mov eax, SRCDEST(ebp) ! eax = dest-src
mov ebx, MESSAGE(ebp) ! ebx = message pointer
mov ecx, SEND ! _send(dest, ptr)
int SYSVEC ! trap to the kernel
pop ebx
pop ebp
ret

__receive:
push ebp
mov ebp, esp
push ebx
mov eax, SRCDEST(ebp) ! eax = dest-src
mov ebx, MESSAGE(ebp) ! ebx = message pointer
mov ecx, RECEIVE ! _receive(src, ptr)
int SYSVEC ! trap to the kernel
pop ebx
pop ebp
ret

__sendrec:
push ebp
mov ebp, esp
push ebx
mov eax, SRCDEST(ebp) ! eax = dest-src
mov ebx, MESSAGE(ebp) ! ebx = message pointer
mov ecx, BOTH ! _sendrec(srcdest, ptr)
int SYSVEC ! trap to the kernel
pop ebx
pop ebp
ret

死锁检测:

  if (dest_ptr->p_flags & SENDING) {
next_ptr = proc_addr(dest_ptr->p_sendto);
while (TRUE) {
if (next_ptr == caller_ptr) return(ELOCKED);
if (next_ptr->p_flags & SENDING)
next_ptr = proc_addr(next_ptr->p_sendto);
else
break;
}
  }

--
※ 来源:·紫 丁 香 bbs.hit.edu.cn·[FROM: 166.111.11.176] 
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.200毫秒