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

📄 main.c

📁 Minix3.11的源码。[MINIX 3是一个为高可靠性应用而设计的自由且简洁的类UNIX系统。]
💻 C
📖 第 1 页 / 共 2 页
字号:
   * that is defined at the kernel level to see which slots to fill in.   */  if (OK != (s=sys_getimage(image)))   	panic(__FILE__,"couldn't get image table: %d\n", s);  procs_in_use = 0;				/* start populating table */  printf("Building process table:");		/* show what's happening */  for (ip = &image[0]; ip < &image[NR_BOOT_PROCS]; ip++) {		  	if (ip->proc_nr >= 0) {			/* task have negative nrs */  		procs_in_use += 1;		/* found user process */		/* Set process details found in the image table. */		rmp = &mproc[ip->proc_nr];	  		strncpy(rmp->mp_name, ip->proc_name, PROC_NAME_LEN); 		rmp->mp_parent = RS_PROC_NR;		rmp->mp_nice = get_nice_value(ip->priority);  		sigemptyset(&rmp->mp_sig2mess);  		sigemptyset(&rmp->mp_ignore);	  		sigemptyset(&rmp->mp_sigmask);  		sigemptyset(&rmp->mp_catch);		if (ip->proc_nr == INIT_PROC_NR) {	/* user process */  			rmp->mp_pid = INIT_PID;			rmp->mp_flags |= IN_USE; 		}		else {					/* system process */  			rmp->mp_pid = get_free_pid();			rmp->mp_flags |= IN_USE | DONT_SWAP | PRIV_PROC; #if DEAD_CODE  			for (sig_ptr = mess_sigs; 				sig_ptr < mess_sigs+sizeof(mess_sigs); 				sig_ptr++)			sigaddset(&rmp->mp_sig2mess, *sig_ptr);#endif		}  		/* Get memory map for this process from the kernel. */		if ((s=get_mem_map(ip->proc_nr, rmp->mp_seg)) != OK)  			panic(__FILE__,"couldn't get process entry",s);		if (rmp->mp_seg[T].mem_len != 0) rmp->mp_flags |= SEPARATE;		minix_clicks += rmp->mp_seg[S].mem_phys + 			rmp->mp_seg[S].mem_len - rmp->mp_seg[T].mem_phys;  		patch_mem_chunks(mem_chunks, rmp->mp_seg);		/* Tell FS about this system process. */		mess.PR_PROC_NR = ip->proc_nr;		mess.PR_PID = rmp->mp_pid;  		if (OK != (s=send(FS_PROC_NR, &mess)))			panic(__FILE__,"can't sync up with FS", s);  		printf(" %s", ip->proc_name);	/* display process name */  	}  }  printf(".\n");				/* last process done */  /* Override some details. INIT, PM, FS and RS are somewhat special. */  mproc[PM_PROC_NR].mp_pid = PM_PID;		/* PM has magic pid */  mproc[RS_PROC_NR].mp_parent = INIT_PROC_NR;	/* INIT is root */  sigfillset(&mproc[PM_PROC_NR].mp_ignore); 	/* guard against signals */  sigfillset(&mproc[FS_PROC_NR].mp_sig2mess); 	/* forward signals */  sigfillset(&mproc[TTY_PROC_NR].mp_sig2mess); 	/* forward signals */  sigfillset(&mproc[MEM_PROC_NR].mp_sig2mess); 	/* forward signals */  /* Tell FS that no more system processes follow and synchronize. */  mess.PR_PROC_NR = NONE;  if (sendrec(FS_PROC_NR, &mess) != OK || mess.m_type != OK)	panic(__FILE__,"can't sync up with FS", NO_NUM);#if ENABLE_BOOTDEV  /* Possibly we must correct the memory chunks for the boot device. */  if (kinfo.bootdev_size > 0) {      mem_map[T].mem_phys = kinfo.bootdev_base >> CLICK_SHIFT;      mem_map[T].mem_len = 0;      mem_map[D].mem_len = (kinfo.bootdev_size+CLICK_SIZE-1) >> CLICK_SHIFT;      patch_mem_chunks(mem_chunks, mem_map);  }#endif /* ENABLE_BOOTDEV */  /* Initialize tables to all physical memory and print memory information. */  printf("Physical memory:");  mem_init(mem_chunks, &free_clicks);  total_clicks = minix_clicks + free_clicks;  printf(" total %u KB,", click_to_round_k(total_clicks));  printf(" system %u KB,", click_to_round_k(minix_clicks));  printf(" free %u KB.\n", click_to_round_k(free_clicks));}/*===========================================================================* *				get_nice_value				     * *===========================================================================*/PRIVATE int get_nice_value(queue)int queue;				/* store mem chunks here */{/* Processes in the boot image have a priority assigned. The PM doesn't know * about priorities, but uses 'nice' values instead. The priority is between  * MIN_USER_Q and MAX_USER_Q. We have to scale between PRIO_MIN and PRIO_MAX. */   int nice_val = (queue - USER_Q) * (PRIO_MAX-PRIO_MIN+1) /       (MIN_USER_Q-MAX_USER_Q+1);  if (nice_val > PRIO_MAX) nice_val = PRIO_MAX;	/* shouldn't happen */  if (nice_val < PRIO_MIN) nice_val = PRIO_MIN;	/* shouldn't happen */  return nice_val;}#if _WORD_SIZE == 2/* In real mode only 1M can be addressed, and in 16-bit protected we can go * no further than we can count in clicks.  (The 286 is further limited by * its 24 bit address bus, but we can assume in that case that no more than * 16M memory is reported by the BIOS.) */#define MAX_REAL	0x00100000L#define MAX_16BIT	(0xFFF0L << CLICK_SHIFT)#endif/*===========================================================================* *				get_mem_chunks				     * *===========================================================================*/PRIVATE void get_mem_chunks(mem_chunks)struct memory *mem_chunks;			/* store mem chunks here */{/* Initialize the free memory list from the 'memory' boot variable.  Translate * the byte offsets and sizes in this list to clicks, properly truncated. Also * make sure that we don't exceed the maximum address space of the 286 or the * 8086, i.e. when running in 16-bit protected mode or real mode. */  long base, size, limit;  char *s, *end;			/* use to parse boot variable */   int i, done = 0;  struct memory *memp;#if _WORD_SIZE == 2  unsigned long max_address;  struct machine machine;  if (OK != (i=sys_getmachine(&machine)))	panic(__FILE__, "sys_getmachine failed", i);#endif  /* Initialize everything to zero. */  for (i = 0; i < NR_MEMS; i++) {	memp = &mem_chunks[i];		/* next mem chunk is stored here */	memp->base = memp->size = 0;  }    /* The available memory is determined by MINIX' boot loader as a list of    * (base:size)-pairs in boothead.s. The 'memory' boot variable is set in   * in boot.s.  The format is "b0:s0,b1:s1,b2:s2", where b0:s0 is low mem,   * b1:s1 is mem between 1M and 16M, b2:s2 is mem above 16M. Pairs b1:s1    * and b2:s2 are combined if the memory is adjacent.    */  s = find_param("memory");		/* get memory boot variable */  for (i = 0; i < NR_MEMS && !done; i++) {	memp = &mem_chunks[i];		/* next mem chunk is stored here */	base = size = 0;		/* initialize next base:size pair */	if (*s != 0) {			/* get fresh data, unless at end */		    /* Read fresh base and expect colon as next char. */ 	    base = strtoul(s, &end, 0x10);		/* get number */	    if (end != s && *end == ':') s = ++end;	/* skip ':' */ 	    else *s=0;			/* terminate, should not happen */	    /* Read fresh size and expect comma or assume end. */ 	    size = strtoul(s, &end, 0x10);		/* get number */	    if (end != s && *end == ',') s = ++end;	/* skip ',' */	    else done = 1;	}	limit = base + size;	#if _WORD_SIZE == 2	max_address = machine.protected ? MAX_16BIT : MAX_REAL;	if (limit > max_address) limit = max_address;#endif	base = (base + CLICK_SIZE-1) & ~(long)(CLICK_SIZE-1);	limit &= ~(long)(CLICK_SIZE-1);	if (limit <= base) continue;	memp->base = base >> CLICK_SHIFT;	memp->size = (limit - base) >> CLICK_SHIFT;  }}/*===========================================================================* *				patch_mem_chunks			     * *===========================================================================*/PRIVATE void patch_mem_chunks(mem_chunks, map_ptr)struct memory *mem_chunks;			/* store mem chunks here */struct mem_map *map_ptr;			/* memory to remove */{/* Remove server memory from the free memory list. The boot monitor * promises to put processes at the start of memory chunks. The  * tasks all use same base address, so only the first task changes * the memory lists. The servers and init have their own memory * spaces and their memory will be removed from the list.  */  struct memory *memp;  for (memp = mem_chunks; memp < &mem_chunks[NR_MEMS]; memp++) {	if (memp->base == map_ptr[T].mem_phys) {		memp->base += map_ptr[T].mem_len + map_ptr[D].mem_len;		memp->size -= map_ptr[T].mem_len + map_ptr[D].mem_len;	}  }}

⌨️ 快捷键说明

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