⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 system.c

📁 操作系统课程设计 在minix3下实现实时进程
💻 C
📖 第 1 页 / 共 2 页
字号:
      krandom.bin[source].r_buf[r_next] = read_clock();  }  if (krandom.bin[source].r_size < RANDOM_ELEMENTS) {  	krandom.bin[source].r_size ++;  }  krandom.bin[source].r_next = (r_next + 1 ) % RANDOM_ELEMENTS;}/*===========================================================================* *				send_sig				     * *===========================================================================*/PUBLIC void send_sig(proc_nr, sig_nr)int proc_nr;			/* system process to be signalled */int sig_nr;			/* signal to be sent, 1 to _NSIG */{/* Notify a system process about a signal. This is straightforward. Simply * set the signal that is to be delivered in the pending signals map and  * send a notification with source SYSTEM. */   register struct proc *rp;  rp = proc_addr(proc_nr);  sigaddset(&priv(rp)->s_sig_pending, sig_nr);  lock_notify(SYSTEM, proc_nr); }/*===========================================================================* *				cause_sig				     * *===========================================================================*/PUBLIC void cause_sig(proc_nr, sig_nr)int proc_nr;			/* process to be signalled */int sig_nr;			/* signal to be sent, 1 to _NSIG */{/* A system process wants to send a signal to a process.  Examples are: *  - HARDWARE wanting to cause a SIGSEGV after a CPU exception *  - TTY wanting to cause SIGINT upon getting a DEL *  - FS wanting to cause SIGPIPE for a broken pipe  * Signals are handled by sending a message to PM.  This function handles the  * signals and makes sure the PM gets them by sending a notification. The  * process being signaled is blocked while PM has not finished all signals  * for it.  * Race conditions between calls to this function and the system calls that * process pending kernel signals cannot exist. Signal related functions are * only called when a user process causes a CPU exception and from the kernel  * process level, which runs to completion. */  register struct proc *rp;  /* Check if the signal is already pending. Process it otherwise. */  rp = proc_addr(proc_nr);  if (! sigismember(&rp->p_pending, sig_nr)) {      sigaddset(&rp->p_pending, sig_nr);      if (! (rp->p_rts_flags & SIGNALED)) {		/* other pending */          if (rp->p_rts_flags == 0) lock_dequeue(rp);	/* make not ready */          rp->p_rts_flags |= SIGNALED | SIG_PENDING;	/* update flags */          send_sig(PM_PROC_NR, SIGKSIG);      }  }}/*===========================================================================* *				umap_bios				     * *===========================================================================*/PUBLIC phys_bytes umap_bios(rp, vir_addr, bytes)register struct proc *rp;	/* pointer to proc table entry for process */vir_bytes vir_addr;		/* virtual address in BIOS segment */vir_bytes bytes;		/* # of bytes to be copied */{/* Calculate the physical memory address at the BIOS. Note: currently, BIOS * address zero (the first BIOS interrupt vector) is not considered, as an  * error here, but since the physical address will be zero as well, the  * calling function will think an error occurred. This is not a problem, * since no one uses the first BIOS interrupt vector.   */  /* Check all acceptable ranges. */  if (vir_addr >= BIOS_MEM_BEGIN && vir_addr + bytes <= BIOS_MEM_END)  	return (phys_bytes) vir_addr;  else if (vir_addr >= BASE_MEM_TOP && vir_addr + bytes <= UPPER_MEM_END)  	return (phys_bytes) vir_addr;#if DEAD_CODE	/* brutal fix, if the above is too restrictive */  if (vir_addr >= BIOS_MEM_BEGIN && vir_addr + bytes <= UPPER_MEM_END)  	return (phys_bytes) vir_addr;#endif  kprintf("Warning, error in umap_bios, virtual address 0x%x\n", vir_addr);  return 0;}/*===========================================================================* *				umap_local				     * *===========================================================================*/PUBLIC phys_bytes umap_local(rp, seg, vir_addr, bytes)register struct proc *rp;	/* pointer to proc table entry for process */int seg;			/* T, D, or S segment */vir_bytes vir_addr;		/* virtual address in bytes within the seg */vir_bytes bytes;		/* # of bytes to be copied */{/* Calculate the physical memory address for a given virtual address. */  vir_clicks vc;		/* the virtual address in clicks */  phys_bytes pa;		/* intermediate variables as phys_bytes */#if (CHIP == INTEL)  phys_bytes seg_base;#endif  /* If 'seg' is D it could really be S and vice versa.  T really means T.   * If the virtual address falls in the gap,  it causes a problem. On the   * 8088 it is probably a legal stack reference, since "stackfaults" are   * not detected by the hardware.  On 8088s, the gap is called S and   * accepted, but on other machines it is called D and rejected.   * The Atari ST behaves like the 8088 in this respect.   */  if (bytes <= 0) return( (phys_bytes) 0);  if (vir_addr + bytes <= vir_addr) return 0;	/* overflow */  vc = (vir_addr + bytes - 1) >> CLICK_SHIFT;	/* last click of data */#if (CHIP == INTEL) || (CHIP == M68000)  if (seg != T)	seg = (vc < rp->p_memmap[D].mem_vir + rp->p_memmap[D].mem_len ? D : S);#else  if (seg != T)	seg = (vc < rp->p_memmap[S].mem_vir ? D : S);#endif  if ((vir_addr>>CLICK_SHIFT) >= rp->p_memmap[seg].mem_vir +   	rp->p_memmap[seg].mem_len) return( (phys_bytes) 0 );  if (vc >= rp->p_memmap[seg].mem_vir +   	rp->p_memmap[seg].mem_len) return( (phys_bytes) 0 );#if (CHIP == INTEL)  seg_base = (phys_bytes) rp->p_memmap[seg].mem_phys;  seg_base = seg_base << CLICK_SHIFT;	/* segment origin in bytes */#endif  pa = (phys_bytes) vir_addr;#if (CHIP != M68000)  pa -= rp->p_memmap[seg].mem_vir << CLICK_SHIFT;  return(seg_base + pa);#endif#if (CHIP == M68000)  pa -= (phys_bytes)rp->p_memmap[seg].mem_vir << CLICK_SHIFT;  pa += (phys_bytes)rp->p_memmap[seg].mem_phys << CLICK_SHIFT;  return(pa);#endif}/*===========================================================================* *				umap_remote				     * *===========================================================================*/PUBLIC phys_bytes umap_remote(rp, seg, vir_addr, bytes)register struct proc *rp;	/* pointer to proc table entry for process */int seg;			/* index of remote segment */vir_bytes vir_addr;		/* virtual address in bytes within the seg */vir_bytes bytes;		/* # of bytes to be copied */{/* Calculate the physical memory address for a given virtual address. */  struct far_mem *fm;  if (bytes <= 0) return( (phys_bytes) 0);  if (seg < 0 || seg >= NR_REMOTE_SEGS) return( (phys_bytes) 0);  fm = &rp->p_priv->s_farmem[seg];  if (! fm->in_use) return( (phys_bytes) 0);  if (vir_addr + bytes > fm->mem_len) return( (phys_bytes) 0);  return(fm->mem_phys + (phys_bytes) vir_addr); }/*===========================================================================* *				virtual_copy				     * *===========================================================================*/PUBLIC int virtual_copy(src_addr, dst_addr, bytes)struct vir_addr *src_addr;	/* source virtual address */struct vir_addr *dst_addr;	/* destination virtual address */vir_bytes bytes;		/* # of bytes to copy  */{/* Copy bytes from virtual address src_addr to virtual address dst_addr.  * Virtual addresses can be in ABS, LOCAL_SEG, REMOTE_SEG, or BIOS_SEG. */  struct vir_addr *vir_addr[2];	/* virtual source and destination address */  phys_bytes phys_addr[2];	/* absolute source and destination */   int seg_index;  int i;  /* Check copy count. */  if (bytes <= 0) return(EDOM);  /* Do some more checks and map virtual addresses to physical addresses. */  vir_addr[_SRC_] = src_addr;  vir_addr[_DST_] = dst_addr;  for (i=_SRC_; i<=_DST_; i++) {      /* Get physical address. */      switch((vir_addr[i]->segment & SEGMENT_TYPE)) {      case LOCAL_SEG:          seg_index = vir_addr[i]->segment & SEGMENT_INDEX;          phys_addr[i] = umap_local( proc_addr(vir_addr[i]->proc_nr),               seg_index, vir_addr[i]->offset, bytes );          break;      case REMOTE_SEG:          seg_index = vir_addr[i]->segment & SEGMENT_INDEX;          phys_addr[i] = umap_remote( proc_addr(vir_addr[i]->proc_nr),               seg_index, vir_addr[i]->offset, bytes );          break;      case BIOS_SEG:          phys_addr[i] = umap_bios( proc_addr(vir_addr[i]->proc_nr),              vir_addr[i]->offset, bytes );          break;      case PHYS_SEG:          phys_addr[i] = vir_addr[i]->offset;          break;      default:          return(EINVAL);      }      /* Check if mapping succeeded. */      if (phys_addr[i] <= 0 && vir_addr[i]->segment != PHYS_SEG)           return(EFAULT);  }  /* Now copy bytes between physical addresseses. */  phys_copy(phys_addr[_SRC_], phys_addr[_DST_], (phys_bytes) bytes);  return(OK);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -