ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®éµã¯ãæ§ã
ãªæŽ»åããµããŒãããããšã§ãããäŸãã°ã第0ç« ã§è¿°ã¹ãã·ã¹ãã ã³ãŒã«ãçšããŠãããã»ã¹ã¯fork
ãåŒã³åºãããšã«ããæ°ããããã»ã¹ãéå§ããããšãã§ããããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯ãããã®ããã»ã¹ãã³ã³ãã¥ãŒã¿äžã®è³æºããæåå²å
±æãã§ããããã«ç®¡çããå¿
èŠããããäŸãã°ãããã»ã¹ãã³ã³ãã¥ãŒã¿äžã«ååšããããã»ããµæ°ãããå€ãã®ããã»ã¹ãçæãããšããŠããå
šãŠã®ããã»ã¹ã¯æ£ããåäœããªããã°ãªããªããå ããŠããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯åããã»ã¹ããç¬ç«ããŠãåäœããããã®ç®¡çãè¡ããªããã°ãªããªããã€ãŸããããããã»ã¹ã«ãã°ãããç°åžžçµäºãããšããŠãããã®ããã»ã¹ãšäŸåé¢ä¿ã®ç¡ãããã»ã¹ã«åœ±é¿ãäžããŠã¯ãªããªããšããããšã§ãããããã»ã¹éã§çžäºäœçšãå¯èœã«ãããããå®å
šãªç¬ç«æ§ã¯éåžžã«åŒ·åãªæ©èœã§ãã; äŸãã°ããŠãŒã¶ã«ãšã£ãŠè€éãªã¿ã¹ã¯ãå®è¡ããããã«è€æ°ã®ããã»ã¹ãçµã¿åãã(äŸãã°ãã€ããªã©)ããšãã§ããã°äŸ¿å©ã§ãããåŸã£ãŠããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®å®è£
ã¯ããå€éåãç¬ç«ãçžäºäœçšãã®3ã€ã®èŠä»¶ãéæããå¿
èŠãããã
æ¬ç« ã§ã¯ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãäžèšã®3ã€ã®èŠä»¶ãæºããããã«ãã©ã®ããã«æ§æãããŠãããã«ã€ããŠæŠèŠã説æããããããå®çŸããããã«ã¯æ§ã
ãªæ段ãååšããããæ¬æžã§ã¯å€ãã®Unixãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ãæ¡çšãããŠãããã¢ããªã·ãã¯ã«ãŒãã«ããšããæ¹åŒãäžå¿ã«ãçŠç¹ãåœãŠãŠèª¬æãè¡ããæ¬ç« ã§ã¯ããã®æ§æããŸãxv6ãåäœãéå§ããæåã®ããã»ã¹ãéå§ãããšãããããã¬ãŒã¹ããŠèª¬æããããã®äžã§ãæ¬æžã§ã¯xv6ãæäŸããäž»ããæœè±¡åã«ã€ããŠç°¡åã«èª¬æãããã€ãŸããã©ã®ããã«ããã»ã¹ãçžäºäœçšãè¡ããã©ã®ããã«ããŠå€éåãç¬ç«ãçžäºäœçšã®èŠæ±ãæºãããããªæ§æãåã£ãŠããã®ãã«ã€ããŠèª¬æãããxv6ã®æ®ã©ã®éšåã¯ãæåã®ããã»ã¹ã«ã€ããŠã®ç¹å¥ãªå Žååãã«ã€ããŠã¯é¿ããŠãããxv6ãæäŸããæšæºçãªæäœãåå©çšããããšã§å®çŸããŠããã以éã®ç« ã§ã¯ãããããã®æœè±¡åã«ã€ããŠãã詳现ã«èª¬æããã
xv6ã¯PCãã©ãããã©ãŒã äžã§ãIntelã®30386ãããåŸç¶ã®("x86")ã®ããã»ããµã§åäœããå€ãã®äœã¬ã€ã€ã®æ©èœ(äŸãã°ãããã»ã¹ã®å®è£
ãªã©)ã¯x86ã®ä»æ§ã«åããŠäœãããŠãããæ¬æžã®èªè
ã¯ããã€ãã®ã¢ãŒããã¯ãã£ã«ã€ããŠå°ãã®ã¢ã»ã³ããªã¬ãã«ã§ã®ããã°ã©ãã³ã°ã®çµéšããããx86ã®ä»æ§ã«ã€ããŠã¯ãå¿
èŠãªãšãã«éæ説æãããä»é²Aã§ãPCãã©ãããã©ãŒã ã«ã€ããŠæŠèŠã説æããŠããã
ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«ã€ããŠèãããšãæåã«æãæµ®ãã¶è³ªåã¯ãäœæ
ãããå¿
èŠãªã®ãïŒãšããããšã§ãããã€ãŸãã誰ããå³0-2ã®ã·ã¹ãã ã³ãŒã«ãã©ã€ãã©ãªãšããŠå®è£
ããŠãããã¢ããªã±ãŒã·ã§ã³ãšãªã³ã¯ãããŠããã°è¯ãã®ã§ã¯ãªãããšèããèš³ã§ããããã®æ¹æ³ã§ã¯ãåã¢ããªã±ãŒã·ã§ã³ã¯åã
ã®ã©ã€ãã©ãªãæã£ãŠãããããããã®ã¢ããªã±ãŒã·ã§ã³ã§é©åãªã©ã€ãã©ãªãæã£ãŠããããã®æ¹æ³ã§ã¯ã¢ããªã±ãŒã·ã§ã³ã¯ããŒããŠã§ã¢ãšçŽæ¥éä¿¡ãè¡ããããŒããŠã§ã¢è³æºãåã
ã®ã¢ããªã±ãŒã·ã§ã³ãæé©ãªæ¹æ³ã§äœ¿çšãã(äŸãã°ãæé«ã®æ§èœãåŸãããã®æ§æãææã®æ§èœãåŸãããã®æ§æã§ã¢ã¯ã»ã¹ãè¡ã)ãçµã¿èŸŒã¿ããã€ã¹åãã®ããã€ãã®å°ããªãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãããªã¢ã«ã¿ã€ã ã·ã¹ãã åãã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ã¯ãã®ãããªæ¹æ³ãåã£ãŠããã
ãã®æ¹åŒã®åé¡ã¯ãã¢ããªã±ãŒã·ã§ã³ãèªç±ã«ã©ã€ãã©ãªã䜿ããããšã§ãããã€ãŸãã¯åã¢ããªã±ãŒã·ã§ã³ããã©ã€ãã©ãªãé©åã«äœ¿ããªãããšããããšã§ãããããã¢ããªã±ãŒã·ã§ã³ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ã©ã€ãã©ãªãå©çšããªããã°ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯æåå²å
±æãã¢ããªã±ãŒã·ã§ã³ã«åŒ·å¶ãããããšãã§ããªããåã¢ããªã±ãŒã·ã§ã³ãæ£ããåäœããŠãããšããããšã«äŸåãããããªããªããäŸãã°å®æçã«ããã»ããµã®ååŸãè«Šããä»ã®ã¢ããªã±ãŒã·ã§ã³ãããã»ãããµãç²åŸããããã«ããªããã°ãªããªãããã®ãããªãååäœæ¥ãå¿
èŠãªãæåå²å
±æã®æ§æã¯ãå
šãŠã®ã¢ããªã±ãŒã·ã§ã³ãæ£ããåäœããŠããããšãä¿¡çšããŠã倧äžå€«ãããããªãããåã¢ããªã±ãŒã·ã§ã³ãçžäºã«ä¿¡çšãªããªããã®ã§ãããšã匷åãªç¬ç«æ§ãæäŸããããšãã§ããªããªãã
匷åãªç¬ç«æ§ãå®çŸããããã«ã¯ãåã¢ããªã±ãŒã·ã§ã³ãçŽæ¥ããŒããŠã§ã¢è³æºã«ã¢ã¯ã»ã¹ããããšãçŠæ¢ãããã®ä»£ããã«åè³æºããµãŒãã¹ãšããŠæœè±¡åããããšãæå¹ã ãšæããããäŸãã°ãåã¢ããªã±ãŒã·ã§ã³ã¯ãã¡ã€ã«ã·ã¹ãã ã«å¯ŸããŠopen
, read
, write
, close
ãªã©ã®ã·ã¹ãã ã³ãŒã«ã§ã®ã¿ã¢ã¯ã»ã¹ããçŽæ¥ãã£ã¹ã¯ã»ã¯ã¿ã¯èªãŸãªãããã«ãããããã«ããã¢ããªã±ãŒã·ã§ã³ããã¹åãå©çšããããšã«ããããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã(ã€ã³ã¿ãã§ãŒã¹ã®å®è£
è
ãšããŠ)ãã£ã¹ã¯ã管çããããšãã§ããããã«ãªãã
åæ§ã«ãUnixã®ã¢ããªã±ãŒã·ã§ã³ãfork
ãçšããŠããã»ã¹ãšããŠåäœããããšã«ãããã¢ããªã±ãŒã·ã§ã³ãç°ãªãããã»ã¹éã§ã¹ã€ããããéã®ãã¬ãžã¹ã¿ã®ã»ãŒããšãªã¹ãã¢ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãå®çŸã§ããããã«ãªããããã«ãããã¢ããªã±ãŒã·ã§ã³ã¯ããã»ã¹ã®ã¹ã€ããã³ã°ã«ã€ããŠæ°ã«æããå¿
èŠãç¡ããªããããã«ãäŸãã°ã¢ããªã±ãŒã·ã§ã³ãç¡éã«ãŒãã«é¥ã£ããšããŠãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã匷å¶çã«ã¢ããªã±ãŒã·ã§ã³ãããã»ããµã®å€ã«ã¹ã€ããããããšãã§ããããã«ãªãã
å¥ã®äŸãšããŠãUnixã®ããã»ã¹ã¯exec
ãçšããããšã«ãããçŽæ¥ç©ççãªã¡ã¢ãªãæäœãã代ããã«ã¡ã¢ãªã€ã¡ãŒãžãæ§ç¯ã§ããããã«ãªããããã«ããããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯ã©ã®é åãã©ã®ããã»ã¹ã䜿ããã決å®ããã¡ã¢ãªé åã足ããªããã°é åã®ç§»åãè¡ãããããã®ã€ã¡ãŒãžãæ ŒçŽããŠããããã®ãã¡ã€ã«ã·ã¹ãã ã®å©äŸ¿æ§ãã¢ããªã±ãŒã·ã§ã³ã«æäŸã§ããããã«ãªãã
ã¢ããªã±ãŒã·ã§ã³éã§å¶åŸ¡ãããçžäºäœçšããµããŒãããããã«ãUnixã®ã¢ããªã±ãŒã·ã§ã³ã¯ãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ã®ã¿ã䜿ãããšãã§ããã(äŸãã°ãç©ççãªã¡ã¢ãªã®äžéšãäºçŽãããšãã£ããããª)ä»ã®å
±æã®ããã®æ¹æ³ãåãããšã¯ãªããUnixã®ãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ã¯å
±æã®ããã®è©³çŽ°ãæœè±¡åããã¿ãŒããã«ããã¡ã€ã«ã·ã¹ãã ããã€ããªã©ã䜿ã£ãŠã¢ããªã±ãŒã·ã§ã³ã®çžäºäœçšãçºçãããšããŠãã詳现ãé ãããšãã§ããããã«ãªãã
å³0-2ã«ç€ºããããªã·ã¹ãã ã³ãŒã«ã®ã€ã³ã¿ãã§ãŒã¹ã¯æ³šææ·±ãèšèšãããå©äŸ¿æ§ã®ããã«ããã°ã©ãã«æäŸãããŠãããããããã®ã€ã³ã¿ãã§ãŒã¹ãå®è£
ããããšã«ãã匷åãªç¬ç«æ§ãå®çŸã§ããŠãããUnixã€ã³ã¿ãã§ãŒã¹ã¯è³æºãæœè±¡åããã ãã§ãªãããããéåžžã«è¯ããã®ã§ãããšããããšã蚌æããŠããã
ã·ã¹ãã ã³ãŒã«ãå©çšãããœãããŠã§ã¢ãšã·ã¹ãã ã³ãŒã«ãå®è£ ããåŽã®ãœãããŠã§ã¢ã®éã§åŒ·ãç¬ç«æ§ãæäŸããããã«ã¯ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãšã¢ããªã±ãŒã·ã§ã³ã®éã«åŒ·åãªå¢çãå¿ èŠã«ãªããã¢ããªã±ãŒã·ã§ã³ã«ãã¹ããã£ãå Žåã«ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãŸã§ããçµäºããã®ã¯é¿ãããããã®ä»£ããã«ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯ã¢ããªã±ãŒã·ã§ã³ãã¯ãªãŒã³ã¢ããããŠãä»ã®ã¢ããªã±ãŒã·ã§ã³ãå®è¡ãç¶ããããã§ããããã®åŒ·åãªç¬ç«æ§ã¯ãã¢ããªã±ãŒã·ã§ã³ã¯ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«ãã£ãŠç®¡çãããããŒã¿æ§é ãæžãæããããšãã§ããŠã¯ãªããªãããšãæå³ãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®åœä»€åãæžãæããããšãã§ããŠã¯ãªããªããšããããšãæå³ããã
ãã®ãããªåŒ·åãªç¬ç«æ§ãæäŸããããã«ãããã»ããµã¯ããŒããŠã§ã¢çãªãµããŒããæäŸãããäŸãã°ãx86ããã»ããµã¯ä»ã®ããã»ããµãšåæ§ã«ãåœä»€ãå®è¡ããããã®2ã€ã®ã¢ãŒããæäŸãã:ã«ãŒãã«ã¢ãŒã ãš ãŠãŒã¶ã¢ãŒã ã§ãããã«ãŒãã«ã¢ãŒãã§ã¯ãããã»ããµã¯ æš©éã®ããåœä»€ ãå®è¡ããããšãã§ãããäŸãã°ãã£ã¹ã¯ïŒãããã以å€ã®I/Oããã€ã¹)ãžã®æžã蟌ã¿ãè¡ãã®ã¯æš©éåœä»€ã§ãããããã¢ããªã±ãŒã·ã§ã³ããŠãŒã¶ã¢ãŒãã§å®è¡ãããŠããäžã§æš©éã®ããåœä»€ãå®è¡ãããšãå®è¡ããŠã¯ãªããªãåœä»€ãå®è¡ãããšããããšã§ããã»ããµã¯ãã®åœä»€ãå®è¡ããããã®ä»£ããã«ã«ãŒãã«ã¢ãŒãã«ç§»è¡ããŠã«ãŒãã«ã¢ãŒãäžã®ãœãããŠã§ã¢ã¯ã¢ããªã±ãŒã·ã§ã³ãã¯ãªãŒã³ã¢ããããã第0ç« ã®å³0-1ã§ã¯ãã®æ§æã瀺ããŠãããã¢ããªã±ãŒã·ã§ã³ã¯ãŠãŒã¶ã¢ãŒãã§ã®ã¿å®è¡ããããšãã§ã(äŸãã°ãæ°ãå ç®ããããªã©)ãããã ãŠãŒã¶ç©ºé ã§å®è¡ããŠãããšåŒã¶ãã«ãŒãã«ç©ºé(ãããã¯ãã«ãŒãã«ã¢ãŒã)ã§å®è¡ããŠãããœãããŠã§ã¢ã®ããšã **ã«ãŒãã« **ãšåŒã¶ã
ãŠãŒã¶ã¢ãŒãã®ã¢ããªã±ãŒã·ã§ã³ããã£ã¹ã¯ã®èªã¿æžãããããå Žåãã¢ããªã±ãŒã·ã§ã³èªèº«ã¯I/Oåœä»€ãå®è¡ããããšãã§ããªããããã«ãŒãã«ã¢ãŒãã«ä»¥éããå¿
èŠããããããã»ããµã¯ãŠãŒã¶ã¢ãŒãããã«ãŒãã«ã¢ãŒãã«ã¹ã€ããããã«ãŒãã«ã«ãã£ãŠæå®ããããšã³ããªãã€ã³ãã«å
¥ãããšãã§ããåœä»€ãæäŸããŠããã(x86ããã»ããµã§ã¯int
åœä»€ã«çžåœããã)ããã»ããµãäžåºŠã«ãŒãã«ã¢ãŒãã«ä»¥éãããšãã«ãŒãã«ã¯ã·ã¹ãã ã³ãŒã«ã®åŒæ°ããã§ãã¯ããã¢ããªã±ãŒã·ã§ã³ãèŠæ±ããæäœã®å®è¡ãèš±å¯ããã決å®ãããã«ãŒãã«ã¢ãŒãã«é·ç§»ããæã«ãã«ãŒãã«ããšã³ããªãã€ã³ããèšå®ããããšãéèŠã§ãã; ããã¢ããªã±ãŒã·ã§ã³ãã«ãŒãã«ã®ãšã³ããªãã€ã³ãã決å®ããããšãã§ããªããã°ãæªæã®ããã¢ããªã±ãŒã·ã§ã³ãåŒæ°ã®å€å®ãè¡ãã³ãŒããã¹ãããããããšãã§ããããã§ããã
ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®éµãšãªãèšèšã®çåãšããŠããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ã©ã®ãããªå Žæãã«ãŒãã«ã¢ãŒãã§å®è¡ããã°è¯ãããšããããšãããããããã·ã³ãã«ãªåçã¯ãã·ã¹ãã ã³ãŒã«ã€ã³ã¿ãã§ãŒã¹ãã«ãŒãã«ãžã®ã€ã³ã¿ãã§ãŒã¹ã§ãããã€ãŸããfork
, exec
, open
, close
, read
, write
ãªã©ã¯å
šãŠã«ãŒãã«ã³ãŒã«ã§ããããã®éžæã¯ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®å®è£
ã¯å
šãŠã«ãŒãã«ã¢ãŒãã§å®è¡ããããšããããšã瀺ããŠããããã®ã«ãŒãã«æ§æãã¢ããªã·ãã¯ã«ãŒãã«ãšåŒã°ããã
ãã®æ§æã§ã¯ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®å
šãŠã®éšåã¯ããã«ããŒããŠã§ã¢æš©éãæã£ãŠå®è¡ãããããã®æ§æã¯ãOSã®èšèšè
ãã©ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®éšåã§ãã«ããŒããŠã§ã¢æš©éãäžèŠã§ãããèæ
®ããå¿
èŠãç¡ããã䟿å©ã§ãããããã«ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ç°ãªãéšåãå調ããããšãç°¡åã§ãããäŸãã°ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯ãããã¡ãã£ãã·ã¥ãšåŒã°ãããã¡ã€ã«ã·ã¹ãã ãšä»®æ³ã¡ã¢ãªã·ã¹ãã ã®éã§å
±æããæ©èœãæã€ããšãã§ããã
ã¢ããªã·ãã¯ãªæ§æã®åŒ±ç¹ã¯ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ç°ãªé åéã®ã€ã³ã¿ãã§ãŒã¹ããã°ãã°è€éãšããããšã§ãã(ããã«ã€ããŠã¯ãæ¬æžã®åŸã®æ¹ã§èŠãŠãã)ãããã«ãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®éçºè
ã¯ééããç¯ãããããªããã¢ããªã·ãã¯ã«ãŒãã«ã§ã¯ãã«ãŒãã«ã¢ãŒãã§ã®ç°åžžçµäºã¯ã«ãŒãã«ãç°åžžçµäºããããšãšåãæå³ã®ãããééãã¯èŽåœå·ãšãªããããã«ãŒãã«ãç°åžžçµäºãããšãã³ã³ãã¥ãŒã¿ã¯åäœããªããªããã¢ããªã±ãŒã·ã§ã³ãåäœããªããªããã³ã³ãã¥ãŒã¿ã¯åèµ·åããããåŸãªããªãã®ã§ããã
ã«ãŒãã«ã®ééãã«ãããªã¹ã¯ãåæžããããã«ã¯ãOSã®èšèšè ã¯ãªãã¹ãã«ãŒãã«ã¢ãŒãã§åäœããé åãæžããããšãèãããæ®ã©ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãæš©éã®å¿ èŠãªåœä»€ãå®è¡ããããšããªããåŸã£ãŠãŠãŒã¶ã¬ãã«ã¢ããªã±ãŒã·ã§ã³ãšããŠåäœãããããšãã§ãããããã«ããã¡ãã»ãŒãžã«ããã¢ããªã±ãŒã·ã§ã³éã§ã®éä¿¡ãã§ããããã«ãªãããã®ã«ãŒãã«ã®æ§æããã€ã¯ãã«ãŒãã«ãšåŒã¶ã å³1-1ã¯ããã€ã¯ãã«ãŒãã«ã®æ§æã瀺ããŠããããã®å³ã§ã¯ããã¡ã€ã«ã·ã¹ãã ã¯ãŠãŒã¶ã¬ãã«ã¢ããªã±ãŒã·ã§ã³ãšããŠåäœããŠããããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ããµãŒãã¹ã¯éåžžã®ãŠãŒã¶ããã°ã©ã ãšããŠåäœãããããµãŒããšåŒã¶ãã¢ããªã±ãŒã·ã§ã³å士ããã¡ã€ã«ãµãŒããéããŠçžäºäœçšãè¡ãããã«ããã€ã¯ãã«ãŒãã«ã¯ãããŠãŒã¶ã¢ãŒãã®ã¢ããªã±ãŒã·ã§ã³ããä»æ¹ã®ã¢ããªã±ãŒã·ã§ã³ã«åããŠã¡ãã»ãŒãžãéä¿¡ããããã®æå°ã®ã¡ã«ããºã ãæäŸããŠãããäŸãã°ãããã·ã§ã«ã®ãããªã¢ããªã±ãŒã·ã§ã³ããã¡ã€ã«ãèªã¿æžãããããã°ããã¡ã€ã«ãµãŒãã«ã¡ãã»ãŒãžãéä¿¡ããŠã¬ã¹ãã³ã¹ãåŸ ãŠã°è¯ãã
ãã€ã¯ãã«ãŒãã«ã§ã¯ãã«ãŒãã«ã€ã³ã¿ãã§ãŒã¹ã¯ããã€ãã®äœã¬ã€ã€ã®é¢æ°ã§æ§æãããŠããããããã¯ã¢ããªã±ãŒã·ã§ã³ãéå§ããããI/Oãæäœããããã¢ããªã±ãŒã·ã§ã³ã«åããŠã¡ãã»ãŒãžãéä¿¡ãããããããã®æ§æã«ããããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®æ®ã©ã®æ©èœã¯ãŠãŒã¶ã¬ãã«ã®ãµãŒããšããŠå®è£ ããããšãã§ããããã«ãªããããã«ãŒãã«ã¯ããå°ãªãã³ãŒãéã«ããå®è£ ããããšãã§ããããã«ãªãã çŸå®ã®äžçã§ã¯ãã¢ããªã·ãã¯ã«ãŒãã«ãšãã€ã¯ãã«ãŒãã«ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®äž¡æ¹ãååšãããäŸãã°Linuxã¯æ®ã©ãã¢ããªã·ãã¯ã«ãŒãã«ãšããŠå®è£ ãããŠããããããã€ãã®OSã®æ©èœã¯ãŠãŒã¶ã¬ãã«ã®ãµãŒããšããŠå®è£ ãããŠãã(äŸãã°ããŠã£ã³ããŠã·ã¹ãã ãªã©)ãxv6ã¯ãUnixãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«ç¿ããã¢ããªã·ãã¯ã«ãŒãã«ãšããŠå®è£ ãããŠãããåŸã£ãŠããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã€ã³ã¿ãã§ãŒã¹ã¯ã«ãŒãã«ã€ã³ã¿ãã§ãŒã¹ã«çžåœãããxv6ã¯å€ãã®æ©èœããµããŒãããªããããxv6ã®ã«ãŒãã«ã¯ãã€ã¯ãã«ãŒãã«ãããå°ããã
(Unixãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãšããŠã®)xv6ã®ç¬ç«æ§ã®åäœã¯ãããã»ã¹ãã§ãããããã»ã¹ã®æœè±¡åã«ãã£ãŠãããããã»ã¹ã¯ä»ã®ããã»ã¹ããã¡ã¢ãªã®å
容ãCPUãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ãªã©ã®æ
å ±ãç Žå£ãããããçã¿èŠããããããããšãé²ãããŸããç¬ç«æ§ã«ããããã»ã¹ãã«ãŒãã«ãã®ãã®ãç Žå£ããŠããŸãããšãé²ã(äŸãã°ãç¬ç«æ§ã匷å¶ããããšã«ããã«ãŒãã«ãä¿è·ããŠãã)ãã«ãŒãã«ã¯ããã»ã¹æœè±¡åãå®è£
ããŠããªããã°ãªãããããã«ãããã°ã®ããããã°ã©ã ãæªæã®ããããã°ã©ã ãã«ãŒãã«ãããã¯ããŒããŠã§ã¢ã«å¯ŸããŠæ»æãä»æãã(äŸãã°ç¬ç«æ§ãç Žããããªæäœ)ããšãé²ãã§ãããã«ãŒãã«ã«ããå©çšãããŠããããã»ã¹ãçæããã¡ã«ããºã ã«ã¯ããŠãŒã¶/ã«ãŒãã«ã¢ãŒããã©ã°ãã¢ãã¬ã¹ç©ºéãã¹ã¬ããã®ã¿ã€ã ã¹ã©ã€ã¹ãªã©ãå«ãŸããŠããããããã«ã€ããŠã¯æ¬ç¯ã«ãŠæŠèŠã瀺ãã
ç¬ç«æ§ãæäŸããããã«ãããã»ã¹ã¯åºæã®æœè±¡åããããã·ã³ãæã£ãŠãããã®ããã«å®çŸããããããã»ã¹ã¯ããã°ã©ã ãšãã©ã€ããŒããªã¡ã¢ãªã·ã¹ãã ããããã¯ãã¢ãã¬ã¹ç©ºéããæäŸããä»ã®ããã»ã¹ããã®é åãèªã¿æžãããããšãé²ããããã»ã¹ã¯åæ§ã«ããã°ã©ã ãèªåã®åœä»€ãå®è¡ããããã®åºæã®CPUãæã£ãŠãããã®ããã«åäœããããã®æœè±¡åãæäŸããã
xv6ã¯ããŒããŠã§ã¢ã«å®è£
ãããŠããããŒãžããŒãã«ãå©çšããŠãåããã»ã¹ãåºæã®ã¢ãã¬ã¹ç©ºéãä¿æããããšãå®çŸããŠãããå³1-2ã«ç€ºãããã«ãã¢ãã¬ã¹ç©ºéã«ã¯ãä»®æ³ã¢ãã¬ã¹ã®0çªããå§ãŸãããŠãŒã¶ã¡ã¢ãªãã®é åãå«ãŸããŠããããŸãåœä»€ãç»å Žãã次ã«ã°ããŒãã«ãªå€æ°ãã¹ã¿ãã¯ããããŠæåŸã«ããŒãé å(malloc
çš)ãååšããŠãããããŒãé åã¯ããã»ã¹ãå¿
èŠã«å¿ããŠæ¡åŒµã§ããããã«é
眮ãããŠããã
åããã»ã¹ã®ã¢ãã¬ã¹ç©ºéã¯ãã«ãŒãã«ã®åœä»€ãšããŒã¿ãããŠãŒã¶ã®ããã°ã©ã ã¡ã¢ãªäžã«åæ§ã«ããããããŠãããããã»ã¹ãã·ã¹ãã ã³ãŒã«ãåŒã³åºããšãããã»ã¹ã®ã¢ãã¬ã¹ç©ºéäžã«ããããããã·ã¹ãã ã³ãŒã«ãåŒã³åºãããããã®æ§æã«ãããã«ãŒãã«ã®ã·ã¹ãã ã³ãŒã«ã®ã³ãŒãã¯ãŠãŒã¶ã¡ã¢ãªãåç
§ããããã«ãªã£ãŠããããŠãŒã¶ã¡ã¢ãªé åãæ¡åŒµãããŠããããšãæ³å®ããŠãxv6ã®ã¢ãã¬ã¹ç©ºéã§ã¯ãã«ãŒãã«ã¯0x80100000ããå§ãŸãé«ãé åã«ããããããŠããã
xv6ã«ãŒãã«ã¯åããã»ã¹ã®å€ãã®ç¶æ
ã管çããŠããããããã¯struct proc
(2353è¡ç®)ã«ããéããããŠãããããã»ã¹ãä¿æããã«ãŒãã«ç¶æ
ã®æãéèŠãªæ
å ±ã¯ãã®ããŒãžããŒãã«ãšãã«ãŒãã«ã¹ã¿ãã¯ãå®è¡ç¶æ
ã§ãããç§éã¯p->xxx
ãšããè¡šèšã«ãã£ãŠãproc
æ§é äœã®ã¡ã³ãå€æ°ãè¡šçŸããããšã«ããã
åããã»ã¹ã¯å®è¡ã®ã¹ã¬ãã(ãããã¯åã«ã¹ã¬ãã)ãä¿æããŠãããããã¯ããã»ã¹ã®åœä»€ãå®è¡ãããã®ã§ãããã¹ã¬ããã¯ãµã¹ãã³ãããããåéããããããããã»ã¹ã®éãééçã«ã¹ã€ããããããã«ã¯ãã«ãŒãã«ã¯çŸåšå®è¡ãããŠããã¹ã¬ããããµã¹ãã³ãããä»ã®ããã»ã¹ã®ã¹ã¬ãããåéãããã¹ã¬ããã®éåžžã«å€ãã®ç¶æ
(ããŒã«ã«å€æ°ãé¢æ°ã³ãŒã«ã®ãªã¿ãŒã³ã¢ãã¬ã¹ãªã©)ã¯ãã¹ã¬ããã®ã¹ã¿ãã¯ã«ä¿æãããŠãããåããã»ã¹ã¯2ã€ã®ã¹ã¿ãã¯ãæã£ãŠãã: ãŠãŒã¶ã¹ã¿ãã¯ãšã«ãŒãã«ã¹ã¿ãã¯ã§ãã(p->kstack
)ãããã»ã¹ããŠãŒã¶åœä»€ãå®è¡ããŠãããªãã°ããŠãŒã¶ã¹ã¿ãã¯ã®ã¿ãå©çšãããŠãããã«ãŒãã«ã¹ã¿ãã¯ã¯ç©ºã§ãããããããã»ã¹ã(ã·ã¹ãã ã³ãŒã«ãå²ã蟌ã¿ãªã©ã«ãã)ã«ãŒãã«ã¢ãŒãã«å
¥ã£ãå Žåãã«ãŒãã«ã³ãŒããå®è¡ãããããã»ã¹ã®ã«ãŒãã«ã¹ã¿ãã¯ãå©çšããã; ããã»ã¹ãã«ãŒãã«ã¢ãŒãäžã¯ããŠãŒã¶ã¹ã¿ãã¯ã¯çŸåšã®ããŒã¿ãä¿æããŠããããå®éã«ã¯äœ¿çšãããŠããªããããã»ã¹ã®ã¹ã¬ããã¯ããŠãŒã¶ã¢ãŒããšã«ãŒãã«ã¢ãŒããããŠãŒã¶ã¹ã¿ãã¯ãšã«ãŒãã«ã¹ã¿ãã¯ãå©çšããŠã¢ã¯ãã£ãã«è¡ãæ¥ãããã«ãŒãã«ã¹ã¿ãã¯ã¯åé¢ãããŠãã(ãããŠãŠãŒã¶ã³ãŒããããä¿è·ãããŠãã)ãã«ãŒãã«ã¯ããã»ã¹ã®ãŠãŒã¶ã¹ã¿ãã¯ãç Žå£ãããŠãããšããŠããã«ãŒãã«ã³ãŒããå®è¡ãããšãã§ãããããªã£ãŠããã
ããã»ã¹ãã·ã¹ãã ã³ãŒã«ãçæãããšãããã»ããµã¯ã«ãŒãã«ã¹ã¿ãã¯ã«é·ç§»ãããŒããŠã§ã¢ã®æš©éã¬ãã«ãäžæãããããããŠã«ãŒãã«åœä»€ãå®è¡éå§ãããã·ã¹ãã ã³ãŒã«ãå®äºãããšãã«ãŒãã«ã¯ãŠãŒã¶ç©ºéã«æ»ã£ãŠãã: ããŒããŠã§ã¢ã®æš©éã¯åã³äžããããŠãŒã¶ã¹ã¿ãã¯ã«åã³ã¹ã€ãããããã·ã¹ãã ã³ãŒã«åœä»€ãå®è¡ãããçŽåŸãããŠãŒã¶åœä»€ãå®è¡ããããããã»ã¹ã®ã¹ã¬ããã¯I/Oãªã©ãåŸ
ã€ããã«å®è¡ãããããã¯ãããããšãã§ããI/Oãå®äºãããšãåã³å®è¡ãåéããã
p->state
ã¯ããã»ã¹ã®çŸåšã®å®è¡ç¶æ
ã瀺ããããã¯ãrun:å®è¡ç¶æ
ããrunning:å®è¡å¯èœç¶æ
ããwait:åŸ
ã¡ç¶æ
(I/Oçš)ããexit:çµäºç¶æ
ãã§ããã
p->pgdir
ã¯ããã»ã¹ã®ããŒãžããŒãã«ãä¿æããŠãããããã¯x86ã®ããŒããŠã§ã¢ãæåŸ
ãããã©ãŒãããã§æ§æãããŠãããxv6ã¯ããŒãžã³ã°ã®ããŒããŠã§ã¢ãåç
§ããéã«ããã»ã¹ã®p->pgdir
ã掻çšãããããã»ã¹ã®ããŒãžããŒãã«ã¯ããã»ã¹ã®ã¡ã¢ãªãå²ãåœãŠãæ
å ±ãæ ŒçŽããããã®ç©çããŒãžã®ã¢ãã¬ã¹æ
å ±ãä¿æãã圹å²ãæ
ã£ãŠããã
xv6ã®æ§é ãããå ·äœçã«çŽ¹ä»ããããã«ãç§éã¯ãã«ãŒãã«ãã«ãŒãã«èªèº«ã®ããã«ãæåã®ã¢ãã¬ã¹ç©ºéãã©ã®ããã«ããŠäœæããã®ãã«ã€ããŠèŠãŠãããã«ãŒãã«ãã©ã®ããã«ããŠã¢ãã¬ã¹ç©ºéãäœæããã©ã®ããã«ããŠæåã®ããã»ã¹ãéå§ããæåã®ããã»ã¹ãäœãããã®ã·ã¹ãã ã³ãŒã«ãã©ã®ããã«ããŠåŒã³åºãã®ãã«ã€ããŠèŠãŠããããããã®æäœããã¬ãŒã¹ããããšã«ãããç§éã¯xv6ãã©ã®ããã«ããã»ã¹ã®ååãªç¬ç«æ§ãæäŸããŠããã®ããèŠãããšãã§ãããæåã®ã¹ããããšããŠååã®ç¬ç«æ§ã¯ã«ãŒãã«ãèªåèªèº«ã®ã¢ãã¬ã¹ç©ºéäžã§å®è¡ããç¶æ ãæ§ç¯ãããšããããã§ããã
PCã®é»æºãå
¥ãããšãPCã¯èªåèªèº«ãåæåããŠãããŒãããŒã(boot loader)ãããã£ã¹ã¯ããã¡ã¢ãªã«å±éããå®è¡ããã
ä»é²Bã«ãã®è©³çŽ°ã説æããŠããã
xv6ã®ããŒãããŒãã¯xv6ã®ã«ãŒãã«ããã£ã¹ã¯ããèªã¿åºããŠãentry
ããå®è¡ãéå§ãã(1040è¡ç®)ã
x86ã®ããŒãžã³ã°ããŒããŠã§ã¢ã¯ã«ãŒãã«ãå®è¡ãããæç¹ã§ã¯æå¹ã«ãªã£ãŠããªã; ä»®æ³ã¢ãã¬ã¹ã¯ç©çã¢ãã¬ã¹ãçŽæ¥ãããã³ã°ããç¶æ
ã«ãªã£ãŠããã
ããŒãããŒããxv6ã®ã«ãŒãã«ãç©çã¢ãã¬ã¹ã®0x100000ãžããŒãããã ã«ãŒãã«ã0x80100000ãžããŒãããªãçç±ã¯ãã«ãŒãã«ã¯èªåèªèº«ã®åœä»€ãšããŒã¿ããå°ããªãã·ã³ã ãšå€§ããªç©çã¡ã¢ãªãªã¢ãã¬ã¹ç©ºéã«é 眮ã§ããªãç¶æ³ãæ³å®ããŠããã®ãããªé 眮ã«ãªã£ãŠããã ã«ãŒãã«ã0x0ã«é 眮ããã®ã§ã¯ãªãã0x100000ã«é 眮ããçç±ã¯ã0xa0000ãã0x100000ã«ã¯I/Oããã€ã¹ãå«ãŸããŠããããã§ããã
ã«ãŒãã«ã®æ®ããå®è¡ã§ããããã«ããããã«ã¯ãentry
ã0x80000000ããå§ãŸãä»®æ³ã¢ãã¬ã¹ç©ºé(KERNBASE
ãšåŒã°ãã)ã0x0ããå§ãŸãç©çã¢ãã¬ã¹ç©ºéã«ãããã³ã°ããã
2ã€ã®é åã®ä»®æ³ã¢ãã¬ã¹ã1ã€ã®ç©çã¡ã¢ãªã®é åã«ãããã³ã°ããããšã¯ãããŒãžããŒãã«ã§ã¯äžè¬çã§ãããåŸã«ããã®ãããªäŸãããã€ã玹ä»ããã
ãã®entry
ã®ããŒãžããŒãã«ã¯main.c
ã«å®çŸ©ãããŠãã(1311è¡ç®)ã
ããŒãžããŒãã«ã®è©³çŽ°ã¯ç¬¬2ç« ã§èŠãŠããããç°¡åã«èª¬æãããšãšã³ããª0ã¯ä»®æ³ã¢ãã¬ã¹0:0x400000ãç©çã¢ãã¬ã¹0:0x400000ã«ãããã³ã°ããŠããã
ãã®ãããã³ã°ã¯entry
ãäœãã¢ãã¬ã¹ã§å®è¡ãããŠããæéã¯å¿
èŠãªèšå®ã§ããããããæçµçã«ã¯åé€ãããã
entry
ã®512çªç®ã¯ä»®æ³ã¢ãã¬ã¹KERNBASE
:KERNBASE
+0x400000ãç©çã¢ãã¬ã¹0:0x400000ã«ãããã³ã°ããŠããã
ãã®ãšã³ããªã¯ã«ãŒãã«ãentry
ãå®è¡ãçµãããšãã«å©çšããã; ã«ãŒãã«ã¯ããé«ãä»®æ³ã¢ãã¬ã¹ã«ãããã³ã°ãããããã«ãŒãã«ã¯åœä»€ãããŒã¿ãããŒãããŒãã®ããŒãããããäœãã¢ãã¬ã¹ã§å®è¡ãããããšãæ³å®ããŠããã
ãã®ãããã³ã°ã«ãããã«ãŒãã«ã®åœä»€ãšããŒã¿ã¯4Mãã€ã以å
ã§ããå¶éãçããã
entry
ã«æ»ããšãentry
ã¯entrypgdir
ã®ç©çã¢ãã¬ã¹ãå¶åŸ¡ã¬ãžã¹ã¿%cr3
ã«ããŒãããã
ããŒãžã³ã°ããŒããŠã§ã¢ã¯entrypgdir
ã®ç©çã¢ãã¬ã¹ãç¥ã£ãŠããªããã°ãªããªãã
ããã¯ãããŒãžã³ã°ããŒããŠã§ã¢ä»®æ³ã¢ãã¬ã¹ã®å€ææ¹æ³ããŸã ç¥ããªãããã§ãã; ãŸã ããŒãžããŒãã«ã¯ååšããŠããªãã®ã§ããã
ã·ã³ãã«entrypgdir
ã¯é«ãã¡ã¢ãªç©ºéã®ã¢ãã¬ã¹ãæãããã¯ãV2P_W0
(0220è¡ç®)ã¯ç©çã¢ãã¬ã¹ãç®åºããããã«KERNBASE
ãæžç®ããããã®ãã¯ãã§ããã
ããŒãžã³ã°ããŒããŠã§ã¢ãæå¹ã«ããããã«ã¯ãxv6ã¯%cr0
ã¬ãžã¹ã¿ã«å¯ŸããŠCR0_PG
ããã©ã°ãèšå®ããã
ããŒãžã³ã°ãæå¹ã«ãªã£ããšããŠããããã»ããµã¯çžå€ãããäœãã¢ãã¬ã¹äžã§å®è¡ãããŠããã
ããã¯entrypgdir
ãäœãã¢ãã¬ã¹ã«ãããã³ã°ãããŠããããã§ããã
ããxv6ãentrypgdir
ãããšã³ããª0ãåãé€ããšãã³ã³ãã¥ãŒã¿ã¯ãæå¹ãªããŒãžã®åŸãã«é
眮ãããŠããåœä»€ãå®è¡ãããšãã«ã¯ã©ãã·ã¥ããŠããŸãã
ããŠãentry
ã¯ã«ãŒãã«ã®Cã³ãŒãã«é·ç§»ããå¿
èŠããããé«ãã¡ã¢ãªã¢ãã¬ã¹ã«é·ç§»ããŠå®è¡ããå¿
èŠãããã
ãŸãã¹ã¿ãã¯ãã€ã³ã¿%esp
ãäœæããã¡ã¢ãªã®ã¹ã¿ãã¯é åã«èšå®ãã(1054è¡ç®)ã
stackãå«ãå
šãŠã®ã·ã³ãã«ã¯é«ãã¢ãã¬ã¹ç©ºéäžã«é
眮ãããŠãããããäœããããã³ãé€å»ããããšããŠãã¹ã¿ãã¯ã¯æå¹ã§ããã
æåŸã«entry
ã¯mainã«ãžã£ã³ãããŠãé«ãã¢ãã¬ã¹ã«é·ç§»ããããã®éæ¥çãªãžã£ã³ããå®çŸããããã«ã¯ã¢ã»ã³ãã©ãå¿
èŠã§ãããããã§ãªããã°ãã³ã³ãã€ã©ã¯PCçžå¯Ÿã®çŽæ¥ãžã£ã³ããçæããäœãã¡ã¢ãªé åã®mainãå®è¡ããŠããŸããPCã¯ã¹ã¿ãã¯äžã«æ ŒçŽãããŠããªããããmainã¯ãªã¿ãŒã³ããããšã¯ã§ããªãã
ããããã¯ãã«ãŒãã«ã¯é«ãã¢ãã¬ã¹ã®mainã«é·ç§»ããŠå®è¡ãéå§ããã
ãããŸã§ã§ãã«ãŒãã«ã¯èªåã®ã¢ãã¬ã¹ç©ºéã§å®è¡ããããšãã§ããããã«ãªã£ãã次ã«ãã«ãŒãã«ã¯ã©ã®ããã«ããŠãŠãŒã¶ã¬ãã«ããã»ã¹ãçæããã©ã®ããã«ããŠã«ãŒãã«ããã»ã¹ãšãŠãŒã¶ã¬ãã«ããã»ã¹ããããŠããã»ã¹ãã®ãã®å士ã®ç¬ç«æ§ãä¿ã€ã®ããèŠãŠããã
mainé¢æ°ãããã€ãã®ããã€ã¹ãšãµãã·ã¹ãã ãåæåãããšãmainé¢æ°ã¯userinit
(1239è¡ç®)ãåŒã³åºããŠæåã®ããã»ã¹ãäœæãããuserinit
é¢æ°ã®æåã®ä»äºã¯ãallocproc
ãåŒã³åºãããšã§ãããallocproc
(2455è¡ç®)ã®ä»äºã¯ããã»ã¹ããŒãã«ã®ã¹ããã(struct proc
æ§é äœ)ãšã«ãŒãã«ã¹ã¬ãããå®è¡å¯èœã«ãªãããã«ãããã»ã¹ã®ç¶æ
ãåæåããããšã§ãããallocproc
ã¯æ°ããããã»ã¹ãçæããããšåŒã³åºãããããäžæ¹ã§userinit
ã¯æåã®ããã»ã¹ã§ããåŒã°ããªããallocproc
ã¯procããŒãã«ãã¹ãã£ã³ããŠãUNUSEDãªç¶æ
ã®ã¹ããããæ¢çŽ¢ãã(2461-2463è¡ç®)ãå©çšããŠããªãã¹ããããæ¢çŽ¢ãããšãallocproc
ã¯ãã®ã¹ãããã®ç¶æ
ãEMBRYO
ãšããŠå©çšã§ããããã«ããŒã¯ããããã»ã¹ã®ãŠããŒã¯ãªpidãå²ãåœãŠã(2451-2469è¡ç®)ã次ã«ãallocproc
ã¯ããã»ã¹ã®ã«ãŒãã«ã¹ã¬ããã®ããã«ã«ãŒãã«ã¹ã¿ãã¯ãå²ãåœãŠããããã¡ã¢ãªå²ãåœãŠã«å€±æãããšãallocproc
ã¯ãã®ç¶æ
ãUNUSEDãšãããŒããè¿ã倱æã§ããããšãéç¥ããã
ããŠãallocproc
ã¯æ°ããããã»ã¹ã®ããã®ã«ãŒãã«ã¹ã¿ãã¯ãæ§ç¯ããªããã°ãªããªããallocproc
ã¯æåã®ããã»ã¹ãçæããã®ãšåæ§ã«ãfork
ã䜿ã£ãŠèšè¿°ããããšãã§ãããallocproc
ã¯ç¹å¥ã«å®¹æãããã«ãŒãã«ã¹ã¿ãã¯ãšãæåã«å®è¡ãéå§ããããšãã«ãŠãŒã¶ç©ºéã«ãæ»ããããã«ããã€ãã®ã«ãŒãã«ã¬ãžã¹ã¿ã®èšå®ãããå³1-4ã«ãæºåã®å®äºããã«ãŒãã«ã¹ã¿ãã¯ã®ã¬ã€ã¢ãŠãã瀺ããallocproc
ã¯ãã®äžé£ã®åäœã®äžã®äžéšåãæ
ããæ°ããããã»ã¹ã®ã«ãŒãã«ã¹ã¬ããããEMBRYO
ãããããã«trapret
ã«ããæåã«å®è¡ããããšãã®ããã®æ»ãå€ãšãªãããã°ã©ã ã«ãŠã³ã¿ãèšå®ãã圹å²ãæ
ã£ãŠãã(2486-2491)ãã«ãŒãã«ã¹ã¬ããã¯ãp->context
ããã³ããŒãããåœä»€ãšãã¬ãžã¹ã¿å
容ãçšããŠå®è¡ãéå§ããããã£ãŠãp->context->eip
ãforkret
ã«èšå®ããããšã«ãã£ãŠãforkret
ã®å
é ããã«ãŒãã«ã¹ã¬ãããåäœããããã«ãªã(2783è¡ç®)ããã®é¢æ°ã¯ã¹ã¿ãã¯ã®åºèŸºã«æ ŒçŽãããŠããã¢ãã¬ã¹ã«æ»ã£ãŠãããã³ã³ããã¹ãã¹ã€ãããå®çŸããããã®ã³ãŒã(2958è¡ç®)ã¯ãã¹ã¿ãã¯ãã€ã³ã¿ãp->context
ã®äžã€äžãæãããã«èšå®ãããallocproc
ã¯p->context
ãã¹ã¿ãã¯ã®äžã«èŒãããã®äžã«trapret
ãèŒããïŒããã«ãããforkret
ã«æ»ãããããšã«ãªããtrapret
ã¯ã«ãŒãã«ã¹ã¿ãã¯ã®ãããã«æ ŒçŽãããŠãããŠãŒã¶ã¬ãžã¹ã¿ãæžãæ»ããããã»ã¹ã«ãžã£ã³ããã(3277è¡ç®)ããã®ã»ããã¢ããã¯ããªãªãžãã«ã®fork
ã®åäœãšæåã®ããã»ã¹ãçæããæé ãšåäžã§ããããæåã®ããã»ã¹ãçæããæé ã§ã¯ãfork
ããåž°ã£ãŠããå®è¡ããã®ã§ã¯ãªãããŠãŒã¶ç©ºéã®ã¢ãã¬ã¹0ããå®è¡ãéå§ããã
第3ç« ã§ãèŠããããŠãŒã¶ãœãããŠã§ã¢ããã«ãŒãã«ãžå¶åŸ¡ã転éããæ¹æ³ã¯ãã·ã¹ãã ã³ãŒã«ãå²ã蟌ã¿ãäŸå€ãªã©ã®å²ã蟌ã¿æ©æ§ãçšããŠå®çŸããããããã»ã¹ãå®è¡äžã«å¶åŸ¡ãã«ãŒãã«ã«é·ç§»ããŠããããŒããŠã§ã¢ãšxv6ã®trapãšã³ããªã³ãŒãããŠãŒã¶ã¬ãžã¹ã¿ãããã»ã¹ã®ã«ãŒãã«ã¹ã¿ãã¯äžã«ä¿åãããuserinit
ã¯æ°ããã¹ã¿ãã¯ã®äžã«å€ãæžã蟌ã¿ãããã»ã¹ãå²ã蟌ã¿ã«ããã«ãŒãã«ã«å
¥ã£ããšãã«ãããããããã«ååšããŠãããã®ãããªç¶æ³ãå®çŸãããããã«ãããã³ãŒããã«ãŒãã«ã¹ã¿ãã¯ããæ»ã£ãŠããŠãããã»ã¹ã®ãŠãŒã¶ã³ãŒãã«é·ç§»ããŠãæ£ããåäœããã®ã§ããããããã®å€ã¯ããŠãŒã¶ã¬ãžã¹ã¿ã«æ ŒçŽãããŠããstruct trapframe
ã§ãããããã§ãæ°ããããã»ã¹ã®ã«ãŒãã«ã¹ã¿ãã¯ã¯å³1-4ã«ç€ºãããã«ãå®å
šã«æºåããããã®ã«ãªã£ãŠããã
æåã®ããã»ã¹ã¯ãå°ããªããã°ã©ã (initcode.S
(8200è¡ç®))ãå®è¡ãããããã»ã¹ã«ã¯ããã°ã©ã ãæ ŒçŽããããã®ç©ççãªã¡ã¢ãªãå¿
èŠã§ãããããã°ã©ã ã¯ãã®ã¡ã¢ãªã«ã³ããŒãããªããã°ãªããªãããŸãããã»ã¹ã¯ã¡ã¢ãªãåç
§ããããã«ããŒãžããŒãã«ãèšå®ããªããã°ãªããªãã
userinit
ã¯setupkvm
(1837è¡ç®)ãåŒã³åºããŠã(æåã«)ããã»ã¹ã®ããŒãžããŒãã«ããã«ãŒãã«ã䜿ãããã«ã¡ã¢ãªã®ã¿ããããã³ã°ããã第2ç« ã§ãã®é¢æ°ã«ã€ããŠã¯è©³çŽ°ã«åŠã¶ãã倧ãŸãã«èŠãã°ãsetupkvm
ãšuserinit
ã¯å³1-2ã«ç€ºããããªã¢ãã¬ã¹ç©ºéãçæããã
æåã®ããã»ã¹ã®ã¡ã¢ãªã®åæå
容ã¯ãinitcode.S
ããã³ããŒããããããã¯ã«ãŒãã«ã®ãã«ãããã»ã¹ã®äžéšã§ããããªã³ã«ããã®ãã€ããªãã«ãŒãã«ã«åã蟌ã¿ã2ã€ã®ç¹å¥ãªã·ã³ãã«ãå®çŸ©ãããããã_binary_initcode_start
ãš _binary_initcode_size
ã§ããããããã¯ãã€ããªã®å Žæãšãµã€ãºã瀺ããŠãããuserinit
ã¯inituvm
ãåŒã³åºãããšã«ãããã®ãã€ããªãæ°ããããã»ã¹ã®ã¡ã¢ãªç©ºéã«ã³ããŒãããinituvm
ã¯ç©çã¡ã¢ãªã®ããŒãžãå²ãåœãŠããã®ã¡ã¢ãªç©ºéãä»®æ³ã¢ãã¬ã¹ã®0çªã«ãããã³ã°ããããããŠãã€ããªãããŒãžã®é åã«ã³ããŒããã®ã§ãã(1903è¡ç®)ã
userinit
ã¯åæã®ãŠãŒã¶ã¢ãŒãã®ç¶æ
ãšãšãã«ããã©ãããã¬ãŒã ãèšå®ãã:%cs
ã¬ãžã¹ã¿ã«ã¯DPL_USER
ã®æš©éã§åäœããŠããSEG_UCODE
ã»ã°ã¡ã³ãã®ããã®ã»ã°ã¡ã³ãã»ã¬ã¯ã¿ãå
¥ã£ãŠãããåæ§ã«%ds
,%es
,%ss
ãæš©éDPL_USER
ãšããŠSEG_UDATA
ãå©çšããã%eflags
ã®FL_IF
ãããã¯ãããŒããŠã§ã¢ã®å²ã蟌ã¿ãèš±å¯ããããã«èšå®ããããããã¯ç¬¬3ç« ã§åã³èª¿æ»ããã
ã¹ã¿ãã¯ãã€ã³ã¿%esp
ã¯ããã»ã¹ã®æã倧ããªæå¹ä»®æ³ã¢ãã¬ã¹ã§ããp->sz
ã«èšå®ãããããã®åœä»€ãã€ã³ã¿ã¯åæåã³ãŒãã®ãšã³ããªãã€ã³ãã§ãããã¢ãã¬ã¹0ã«èšå®ãããã
é¢æ°userinit
ã¯p->name
ãinicode
ã«èšå®ãããããã¯ãããã°çšã§ãããp->cwd
ãèšå®ããããšã«ãããããã»ã¹ã®çŸåšã®ã¯ãŒãã³ã°ãã£ã¬ã¯ããªãèšå®ãã;第6ç« ã§ã¯ãnamei
ã«ã€ããŠè©³çŽ°ã調æ»ããŠããã
äžåºŠããã»ã¹ãåæåããããšãuserinit
ã¯p->state
ãRUNNABLE
ã«èšå®ããã¹ã±ãžã¥ãŒã«å¯èœãªç¶æ
ã§ããããšãããŒã¯ããã