/* * INIT_TASK is used to set up the first task table, touch at * your own risk!. Base=0, limit=0x9ffff (=640kB) */// 下面的就是进程0的各个参数的具体值 #define INIT_TASK \ /* state etc */ { 0,15,15, \ // 0是说可以跑,而不是正在跑 /* signals */0,{{},},0, \ /* ec,brk... */0,0,0,0,0,0, \ /* pid etc.. */0,-1,0,0,0, \ /* uid etc */0,0,0,0,0,0, \ /* alarm */0,0,0,0,0,0, \ /* math */0, \ /* fs info */-1,0022,NULL,NULL,NULL,0, \ /* filp */ {NULL,}, \ { \ {0,0}, \ /* ldt */ {0x9f,0xc0fa00}, \ {0x9f,0xc0f200}, \ }, \ /*tss*/ {0,PAGE_SIZE+(long)&init_task,0x10,0,0,0,0,(long)&pg_dir,\ 0,0,0,0,0,0,0,0, \ 0,0,0x17,0x17,0x17,0x17,0x17,0x17, \ _LDT(0),0x80000000, \ {} \ }, \ }
structtask_struct {// 非常非常非常重要,操作系统里最核心的东西 /* these are hardcoded - don't touch */ long state; /* -1 unrunnable, 0 runnable, >0 stopped *///状态 long counter; //时间片 long priority; long signal; structsigactionsigaction[32]; long blocked; /* bitmap of masked signals */ /* various fields */ int exit_code; unsignedlong start_code,end_code,end_data,brk,start_stack; //malloc从这里划 long pid,father,pgrp,session,leader; unsignedshort uid,euid,suid; unsignedshort gid,egid,sgid; long alarm; long utime,stime,cutime,cstime,start_time; unsignedshort used_math; /* file system info */ int tty; /* -1 if no tty, so it must be signed */ unsignedshort umask; structm_inode * pwd; structm_inode * root; structm_inode * executable; unsignedlong close_on_exec; structfile * filp[NR_OPEN]; /* ldt for this task 0 - zero 1 - cs 2 - ds&ss */ structdesc_structldt[3]; /* tss for this task */ structtss_structtss; };
after_page_tables: pushl $0 # These are the parameters to main :-) pushl $0 pushl $0 pushl $L6 # return address for main, if it decides to. pushl $_main ; 后面把这个pop出来 jmp setup_paging
structtss_struct { long back_link; /* 16 high bits zero */ long esp0; long ss0; /* 16 high bits zero */ long esp1; long ss1; /* 16 high bits zero */ long esp2; long ss2; /* 16 high bits zero */ long cr3; long eip; long eflags; long eax,ecx,edx,ebx; long esp; long ebp; long esi; long edi; long es; /* 16 high bits zero */ long cs; /* 16 high bits zero */ long ss; /* 16 high bits zero */ long ds; /* 16 high bits zero */ long fs; /* 16 high bits zero */ long gs; /* 16 high bits zero */ long ldt; /* 16 high bits zero */ long trace_bitmap; /* bits: trace 0, bitmap 16-31 */ structi387_structi387; };
14.进程0的task_struct在哪?具体内容是什么?给出代码证据。
init/main.c sched_init();
kernel/sched.c
1 2 3 4 5 6 7 8 9 10 11 12 13
voidsched_init(void)//调度程序的初始化子程序 { int i; structdesc_struct * p;
if (sizeof(struct sigaction) != 16) panic("Struct sigaction MUST be 16 bytes"); //致命错误 set_tss_desc(gdt+FIRST_TSS_ENTRY,&(init_task.task.tss)); // 设置初始任务(任务 0)的任务状态段描述符和局部数据表描述符(include/asm/system.h,65)。 set_ldt_desc(gdt+FIRST_LDT_ENTRY,&(init_task.task.ldt));
/* * Get physical address of first (actually last :-) free page, and mark it * used. If no free pages left, return 0. */ unsignedlongget_free_page(void) { registerunsignedlong __res asm("ax");