linux内核分析-初始化分析
参考我提供的三个文件:bootsect.txt,head.txt,setup.txt static int boot_cpu = 1; /* "current" has been set up, we need to load it now *//*定义双处理器用*/ if (!boot_cpu) boot_cpu = 0; #endif
paging_init(unsigned long start_mem, unsigned long end_mem)(会在以后的内存管理子系统分析时详细介绍) { int i; struct memclust_struct * cluster; struct memdesc_struct * memdesc;
/* initialize mem_map[] */ start_mem = free_area_init(start_mem, end_mem);/*遍历查找内存的空闲页*/
/* find free clusters, update mem_map[] accordingly */ memdesc = (struct memdesc_struct *) (hwrpb->mddt_offset + (unsigned long) hwrpb); cluster = memdesc->cluster; for (i = memdesc->numclusters ; i > 0; i--, cluster++) { unsigned long pfn, nr;
/* Bit 0 is console/PALcode reserved. Bit 1 is non-volatile memory -- we might want to mark this for later */ if (cluster->usage & 3) continue; pfn = cluster->start_pfn; if (pfn >= MAP_NR(end_mem)) /* if we overrode mem size */ continue; nr = cluster->numpages; if ((pfn + nr) > MAP_NR(end_mem)) /* if override in cluster */ nr = MAP_NR(end_mem) - pfn;
while (nr--) clear_bit(PG_reserved, &mem_map[pfn++].flags); } memset((void *) ZERO_PAGE(0), 0, PAGE_SIZE);
return start_mem; }
{ char *next; char *quote; int args, envs;
if (!*line) return; args = 0; envs = 1;/* TERM is set to 'linux' by default */ next = line; while ((line = next) != NULL) { quote = strchr(line,'"'); next = strchr(line, ' '); while (next != NULL && quote != NULL && quote < next) { next = strchr(quote+1, '"'); if (next != NULL) { quote = strchr(next+1, '"'); next = strchr(next+1, ' '); } } if (next != NULL) *next++ = 0; /* * check for kernel options first.. */ if (!strcmp(line,"ro")) { root_mountflags |= MS_RDONLY; continue; } if (!strcmp(line,"rw")) { root_mountflags &= ~MS_RDONLY; continue; } if (!strcmp(line,"debug")) { console_loglevel = 10; continue; } if (!strcmp(line,"quiet")) { console_loglevel = 4; continue; } if (!strncmp(line,"init=",5)) { line += 5; execute_command = line; args = 0; continue; } if (checksetup(line)) continue;
if (strchr(line,'=')) { if (envs >= MAX_INIT_ENVS) break; envp_init[++envs] = line; } else { if (args >= MAX_INIT_ARGS) break; argv_init[++args] = line; } argv_init[args+1] = NULL; envp_init[envs+1] = NULL; }
|