ãã¼ãããã®OSèªä½å ¥éãã Rust ã§ãã (第1ç« ï½ç¬¬4ç« )
ã¼ãããã®OSèªä½å ¥é ã ä¸éãåçµ ããã¨ããã Rust ã«ç§»æ¤ããããªã£ãã®ã§ãã£ã¦ããã¾ãã
- 次å: 「ゼロからのOS自作入門」を Rust でやる (第5章) - gifnksmの雑多なメモ
- é¢é£è¨äºä¸è¦§: ゼロからのOS自作入門 カテゴリーの記事一覧 - gifnksmの雑多なメモ
github.com Rust 㧠OS ãªã®ã§åå㯠"éOS" ã§ããå®ç´ã§ãã "sabios" ã§ãã£ã¨ã°ã°ã£ãã¨ãããã¹ãã¤ã³èªã§ "è³¢ã" ã£ã¦æå³ãããããã§ãã è¯ãã§ããã ã¯ã¬ãã¼ãªå®è£ ãç®æãããã¨ããã§ãã
æ¹é
ãã¼ãããã®OSèªä½å ¥éãã®ç« ç«ã¦ã«æ²¿ã£ã¦1ç« ããé çªã«å®è£ ãã¦ããã¾ãã C++ ã§ä¸éãåçµã¯å®äºãã¦ããã®ã§å®æ形㮠OS ã¨é¢ä¿ãªãç¯ã¯ã¹ããããã¦ããã¾ãã
ãã£ãã Rust ã§å®è£ ããã®ã§å®å ¨æ§ãæ½è±¡åã¨ããç¹ã§ MikanOS ã¨ã®å·®ç°ãåºãããè¯ããªã¨æã£ã¦ãã¾ãã
ããã§ã¯æ©éãã£ã¦ããã¾ãããã
第1ç« ï½3ç«
UEFI ã§ãã¼ããã¼ãã¼ãä½æãèªä½ã«ã¼ãã«ãèµ·åããç« ã§ãã
uefi-rs
ãå©ç¨ãã¦ãã¼ããã¼ãã¼ãèªä½ãã¦ããæ¹ãå¤ãã£ãã§ããã
ä»åã¯æ¥½ãã㦠Writing an OS in Rust ã®ä½è
ãæä¾ãã¦ãã bootloader
ãå©ç¨ãããã¨ã«ãã¾ããã
bootloader
㯠2021/5/5 ã«å
¬éããã v0.10 ãã UEFI ã§ã®ãã¼ãã«å¯¾å¿ãã¦ãã¾ãã
bootloader
ã使ã£ããã¼ããã¼ãã¼ã®ä½æã¯ç¹æ®ãªæé ãè¸ãå¿
è¦ãããã®ã§ããã Writing an OS in Rust ã® 3rd edition ã®ãã©ãã ã® post-02 ã§è©³ãã説æããã¦ããã®ã§ããã«å¾ã£ã¦å®è£
ãã¾ããå½è©²è¨äºã§ã¯ cargo ã® alias ãå©ç¨ãã¦ãã«ãã³ãã³ãå®è¡ãç°¡æåãã¦ãã¾ããããã¾ã好ã¿ã§ã¯ãªãã£ãã®ã§ sabios ã§ã¯ Makefile ãæ¡ç¨ãã¾ããã
è¨äºã«å¾ã£ã¦å®è£ ãã¦ããã¨ããä¸æè°ã3ç« å®äºæç¹ã® MikanOS ã¨ã»ã¨ãã©åãç»é¢åºåãå¾ããã¾ããã ããã«ã¦3ç« ã¾ã§å®äºã¨ãã¾ãã (2ç« ã®ã¡ã¢ãªããããã¡ã¤ã«ã®ä½æ㯠UEFI å´ã®å¦çãªã®ã§çç¥ãã¾ããã)
3ç« å®äºæç¹ã®ã½ã¼ã¹ã¯ä»¥ä¸ã
第4ç«
æ¬æ ¼çãªOSå®è£ ã®å§ã¾ãã§ãã æåã®ä¸æ©ã¯ãã¬ã¼ã ãããã¡ãå©ç¨ããç»é¢æç»ç¨ã¢ã¸ã¥ã¼ã«ã®ä½æã§ãã
æåã®å®è£
ã¾ãã¯ç´°ããäºãæ°ã«ããã«ã Rust ã®ã¹ã¿ã¤ã«ã§ãã¿ã«æ¸ãã¦ã¿ã¾ããã
ãã¬ã¼ã ãããã¡ã¸ã®æç»ãæ
å½ãã framebuffer::Drawer
æ§é ä½ãä½æãã¾ããã
ãã®æ§é ä½ã main
é¢æ°å
ã§åæåããæç»å¦çãå¼ã³åºãã¦ãã¾ãã
ç¹ã«é£ãããã¨ã¯ãªãã§ããã
ãã¾ã㧠MikanOS æ¬ã§ã¯å¯¾å¿ãã¦ããªãã£ã PixelFormat::U8
ãªãã¬ã¼ã ãããã¡ã«ã対å¿ãã¦ãã¾ãã
Rust ã§ã¯åä¸é åã«å¯¾ãã &mut
ã®åç
§ãè¤æ°åæã«åå¨ãã㨠Undefined Behavior ã¨ãªãããã ãã¼ããã¼ãã¼ãã渡ããã FrameBuffer
ãããããã¡ã®ã¹ã©ã¤ã¹ &mut [u8]
ãåãåºãã¦å©ç¨ããã®ã§ã¯ãªãã FrameBuffer
æ§é ä½ãã®ãã®ã framebuffer::Drawer
ã®ãã£ã¼ã«ãã¨ãã¦ä¿æããããã«ãã¦ãã¾ãã
ãã¬ã¼ã ãããã¡ãã©ãããã§ã使ããããã«ãã
ããã§æç»ã¯ã§ããããã«ãªã£ãã®ã§ããããã®ã¾ã¾ã§ã¯ãã¬ã¼ã ãããã¡ã«æç»ããããã« framebuffer::Drawer
ã¸ã®åç
§ããã¡ãã¡ã«åãåãå¿
è¦ãããã¾ãã
ããã§ã¯ãã¾ãã«ãä¸ä¾¿ãªã®ã§ framebuffer::Drawer
åã®ã°ãã¼ãã«å¤æ° (static
å¤æ°) ãä½æããã«ã¼ãã«å
ã®ã©ãããã§ãã¢ã¯ã»ã¹ã§ããããã«ãã¾ãã
FrameBuffer
ã¯ã«ã¼ãã«ã®ã¨ã³ããªãã¤ã³ã (kernel_main
) ã®å¼æ°ã¨ãã¦æ¸¡ãããæ
å ±ã§ãããããstatic å¤æ°ã®åæåã®ã¿ã¤ãã³ã°ã§ã¯å©ç¨ãããã¨ãã§ãã¾ããã
static å¤æ°ã®åæåã®ã¿ã¤ãã³ã°ã§ã¯æªåæåç¶æ
ã®ã¾ã¾ã«ãã¦ããã kernel_main
ãã framebuffer::init
ãå¼ã³åºãã¿ã¤ãã³ã°ã§åæåãã¾ãã
ãã®ãããªåæååä½ãå®ç¾ããããã« conquer_once::OnceCell
ãå©ç¨ãã¦ãã¾ãã
ã¾ãã static å¤æ°ã¸ã® mutable ã¢ã¯ã»ã¹ãå®ç¾ããããã« spin::Mutex
ãå©ç¨ãã¦ãã¾ãã
spin::Mutex
㯠no_std
ã§ãå©ç¨ã§ãã Mutex ã§ããååã®éãã¹ãã³ããã¯ã使ããã¦ãã¾ãã
ã©ã¡ãã® crate ã Writing an OS in Rust ã§ç¥ãã¾ãã (post-03 㨠post-12)ãæ¬å½ã«è¯ãè¨äºã§ãã
ãã¬ã¼ã ãããã¡ã®æ§è½æ¹å
ããã¾ã§ã§ãã¬ã¼ã ãããã¡ã使ãããã®åºæ¬çãªæ©è½ã¯ä¸éãæãã¾ããã ç¶ãã¦ã¯æ§è½æ¹åã§ãã MikanOS ã§ã¯ C++ ã®ä»®æ³é¢æ°ã使ããã¨ã§ override ã«ããæ¡ä»¶åå²ã®åæ°ãå¤§å¹ ã«æ¸ãããã¨ã§æ§è½æ¹åãã¦ãã¾ããã sabios ã§ã¯ dyn Trait ã使ã£ãåçãã£ã¹ãããã«ããåæ§ã®æ§è½æ¹åãå®ç¾ãã¾ããã ç»é¢ãè¦ãªããã¹ãããã¦ã©ããã§æç»é度ãè¨æ¸¬ããã¨ãããã ããã2åå¼·é«éã«ãªã£ãããã§ãããã£ããï¼
framebuffer::Drawer
å
¨ä½ã dyn Trait åããã®ã¯ããããããªããããªæ°ãããã®ã§ãåå²ã®ããé¨åã®ã¿ dyn Trait ã¨ãã¦æ½åºãã¦ãã¾ãã
æ§è½æ¹åã®åº¦åãã測å®ãããããã«ã¼ãã«ã release ãã«ãã§ããããã« Makefile ãæ¹é ãã¦ãã¾ã (ã³ãããã¡ãã»ã¼ã¸ã typo ãã¦ã¦æå³ä¸æã«ãªã£ã¦ã¾ãã)ã
ã¾ã¨ã
ãã¼ãããã®OSèªä½å ¥éãã®ç¬¬4ç« ã¾ã§ã Rust ã§å®è£ ãã¾ããã ããã¾ã§ã¯å¤§ããªå¼ã£ãããããªãã¹ã ã¼ãºã«å®è£ ã§ãã¾ããã 次ã®è¨äºã§ã¯ç¬¬5ç« ä»¥éãå®è£ ãã¦ããã¾ãã
- 次å: 「ゼロからのOS自作入門」を Rust でやる (第5章) - gifnksmの雑多なメモ
- é¢é£è¨äºä¸è¦§: ゼロからのOS自作入門 カテゴリーの記事一覧 - gifnksmの雑多なメモ