ãã¼ãããã®OSèªä½å ¥éãã Rust ã§ãã (第10ç« ï½ç¬¬12ç« )
ä»åã¯ã¾ã¨ãã¦3ç« ã§ãã
- ã·ãªã¼ãºæåã®è¨äº: 「ゼロからのOS自作入門」を Rust でやる (第1章~第4章) - gifnksmの雑多なメモ
- åå: 「ゼロからのOS自作入門」を Rust でやる (第9章) - gifnksmの雑多なメモ
- 次å: 「ゼロからのOS自作入門」を Rust でやる (第13章) - gifnksmの雑多なメモ
- é¢é£è¨äºä¸è¦§: ゼロからのOS自作入門 カテゴリーの記事一覧 - gifnksmの雑多なメモ
第10ç«
ã¦ã£ã³ãã¦ã表示ãã¦æä½ã§ããããã«ããç« ã§ãã ä¸æ°ã«GUIã£ã½ããªãã¾ããã
ãã¦ã¹ã«ã¼ã½ã«ãç»é¢å¤ã«é£ã³åºãã®ãä¿®æ£ (day10a)
ãã¦ã¹ã«ã¼ã½ã«ãç»é¢ç«¯ã«åããã¨ç»é¢ç«¯ããé£ã³åºãã¦ãã¾ãã®ãä¿®æ£ãã¾ããã
C++çã§ã¯ç»é¢ããé£ã³åºãããã¦ã¹ãå対å´ã®ç«¯ããç¾ããããã«ãªã£ã¦ãã¾ããã Rust çã§ã¯æç»æã«åº§æ¨ã®ç¯å²ãã§ãã¯ãè¡ã£ã¦ãããããã®ãããªåä½ã«ã¯ãªã£ã¦ãã¾ããã§ãããã ãã¦ã¹ãç»é¢ç«¯ãã移åãã¦é ãã¦ãã¾ãããã«ã¯ãªã£ã¦ããããä¿®æ£ãã¾ããã
ã¡ã¤ã³ã¦ã¤ã³ãã¦ã追å (day10b)
ã¡ã¤ã³ã¦ã¤ã³ãã¦ã追å ãã¾ãã
ã¡ã¤ã³ã¦ã¤ã³ãã¦å¦çå°ç¨ã® CoTask
ãä½æãã表示ããããã«ãã¦ãã¾ãã
é«éã«ã¦ã³ã¿ã追å (day10c)
ã¤ãã³ãã«ã¼ãã®ã«ã¼ãæ¯ã«ã«ã¦ã³ãã¢ããããã«ã¦ã³ã¿ãä½æããå¤ãã¡ã¤ã³ã¦ã¤ã³ãã¦ã«è¡¨ç¤ºãã¾ãã
C++çã¨ã¯æ§é ãç°ãªãã¤ãã³ãã«ã¼ã㯠async/await ã® executor ã¨ãã¦å®è£
ããã¦ãããããã«ã¼ãå
ã«ç°¡åã«ã«ã¦ã³ãã¢ããå¦çã追å ãããã¨ã¯ã§ãã¾ããã
ãã®ãããä¸åº¦ã¤ãã³ãã«ã¼ãã«å¶å¾¡ãæ»ããå¾å³å¾©å¸°ãããã㪠Future
ã§ãã Yield
ãä½æã main_window
ã®ã¤ãã³ãå¦çä¸ã§å©ç¨ããããã«ãã¾ããã
ããã«ããã main_window
ã® CoTask
ããã¤ãã³ãã«ã¼ãã«ä¸æ¦å¶å¾¡ãæ»ããããã«ãªãã¾ãã
å¶å¾¡ãæ»ããåæ°ãã«ã¦ã³ããããã¨ã§ã«ã¦ã³ã¿ã¼ã®ä»£æ¿ã¨ãã¾ããã
æç»ç¯å²ã®å¶éã«ããé«éå (day10d)
å¾æ¥å¦çã§ã¯ç»é¢ã®ä¸é¨åãå¤æ´ãããå ´åã§ãç»é¢å ¨ä½ãåæç»ãã¦ãã¾ããã ãããæ´æ°ããã£ãã¦ã¤ã³ãã¦ã®ç¯å²ã®ã¿åæç»ããããã«å¤æ´ããç»é¢æç»ãé«éåãã¾ãã
å®è£ æ¹éã¯C++çã¨åãã§ãã
Window
㨠WindowDrawer
ãçµ±åãã
Window
㨠WindowDrawer
ã¯ããããå¥ã®æ§é ä½ã¨ãã¦å®ç¾©ãã¦ãã¾ãããã両è
ãçµ±åãã Window
ã Draw
ãå®è£
ããããã«ãã¾ããã
ã³ã¼ããã·ã³ãã«ã«ãªãã¾ããã
Mutex::with_lock
ã追å
å CoTask
ã®ã¤ãã³ãã«ã¼ãå
ã§ä¸æçã« Window
ã®ããã¯ãåå¾ããæç»å®äºå¾ã¢ã³ããã¯ããã¨ããå¦çãä½åº¦ãç»å ´ãã¦ãã¾ãããã㯠& ã¢ã³ããã¯ã®åºéãå¶å¾¡ãããã以ä¸ã®ããã«ãããã¯ãå¿
è¦ãªã®ã§ãããã³ã¼ããèªã¿ã¥ããæãããããå¼æ°ã®ã¯ãã¼ã¸ã£ã«ããã¯ãåã£ãå¤ã渡ã Mutex::with_lock
ãç¨æãã¾ããã
// æ¢åå¦ç let mut window = ...; { let mut window = window.lock(); window.fill_rect(...); window.fill_rect(...); } // æ¹é å¾å¦ç window.with_lock(|window| { window.fill_rect(...); window.fill_rect(...); });
å¾è ã®æ¹ãããã¯åºéãæ確ã«ãªã£ã¦è¯ãããªã¼ã¨ããæ°æã¡ã§ãã
ããã¯ãããã¡ã«ããã¡ãã¤ãã解æ¶ãã (day10e)
ããã¾ã§ã¯ç»é¢ã®æç»æã«ç´æ¥ãã¬ã¼ã ãããã¡ã«æç»ãã¦ãã¾ããã ãã®ãããæç»éä¸ã®ç¶æ ãç»é¢ã«è¡¨ç¤ºãããããããã¦ã¹ã«ã¼ã½ã«ãªã©ãã¡ãã¤ãã¦è¡¨ç¤ºããããã¨ãããã¾ããã ããã解æ¶ãããããããã¯ãããã¡ãã¨ãããããã¡ãå°å ¥ãã¾ãã åã¦ã¤ã³ãã¦ã®æç»æã«ç´æ¥ãã¬ã¼ã ãããã¡ã«æç»ããã®ã§ã¯ãªããä¸æ¦ããã¯ãããã¡ã«ãã¹ã¦ã®ã¦ã¤ã³ãã¦ãæç»ãã å®äºå¾ã«ããã¯ãããã¡ã®å 容ããã¬ã¼ã ãããã¡ã«ã³ãã¼ããã¨ããå®è£ ã¸ã¨å¤æ´ãã¾ãã ããã«ããã¡ãã¤ããå®å ¨ã«è§£æ¶ãã¾ãã
ã¦ã¤ã³ãã¦ããã©ãã°ã§ããããã«ãã (day10f)
ã¦ã¤ã³ãã¦ããã©ãã°ãããã¨ã§ç§»åã§ããããã«ãã¾ãã
mouse
ã® CoTask
ã§ãã¦ã¹ã®ãã¿ã³æ¼ä¸ãæ¤ç¥ã§ããããã«ããããã«å¿ãã¦ã¦ã¤ã³ãã¦ããã©ãã°ã§ããããã«ãã¾ãã
ãã¦ã¹ã«ã¼ã½ã«ã®ä¸ã«ããã¦ã¤ã³ãã¦ã® LayerId
ãåå¾ããããã LayerManager
ã¸åãåããããããªã¤ã³ã¿ãã§ã¼ã¹ãç¨æãã¦ãã¾ãã
ããã¾ã§ã® LayerManager
é¢é£å¦çã¨ç°ãªãã LayerManager
å´é¢æ°ããã®æ»ãå¤ãå¼ã³åºãå
ã¸è¿ãå¿
è¦ãããã¾ãããmouse
㨠layer_manager
ã¯ããããç°ãªã CoTask
ã§åä½ãã¦ãããããé常ã®é¢æ°ã®ããã«å¤ã渡ããã¨ã¯ã§ãã¾ããã
CoTask
éãè·¨ãã£ã¦å¤ãããã¨ãããããã«ã¯ãã£ã³ãã«ãå©ç¨å¯è½ã§ãããããã¾ã§ã«ä½æãããã£ã³ãã«ã¯ä½åº¦ãç¹°ãè¿ãã¦å¤ãéä¿¡ããããã®ãã®ã§ãããé¢æ°ã®æ»ãå¤ã¨ãã£ãå¤ãä¸åº¦ã ã渡ããããªä½¿ãæ¹ã«ã¯åãã¦ãã¾ããã
ãã®ããã oneshot
ã¨ãããã£ã³ãã«ãä½æã使ãããã«ãã¦ãã¾ãã
ãã¦ã¹ã®ãã©ãã°é¢é£å¦çã layer
ã® CoTask
ã¸ã¨ç§»åãã
å
ã»ã©ã®ç¯ã§ãã¦ã¹ã®ãã©ãã°å¦çãå®è£
ããã°ããã§ãããä»å¾ãã®ãããªãã¦ã¹ããã®å
¥åã«å¿ãã¦ã¦ã¤ã³ãã¦ãå¶å¾¡ãããããªå¦çãå¢ãã¦ããã¨ã mouse
㨠layer
ã® CoTask
éã§ã®ããã¨ããå¢ãããã¨ã¨ãªããå¹çãæªãã§ããããªã«ãããããã°ã©ãã³ã°ãããã©ãããã§ãã
ãã®ããã mouse
ã® CoTask
ã¯ãã¦ã¹ãã¿ã³ã®æ¼ä¸æç¡çãå¤å®ããã ãã¨ãã layer
ã® CoTask
ã§ãã©ãã°çã®å¦çãè¡ãããã«ãã¾ããã
CoTask
éã®å½¹å²åæ
ãæ確ã«ãªã£ã¦è¯ãæãã§ããã
ã¡ã¤ã³ã¦ã¤ã³ãã¦ã ãããã©ãã°å¯è½ã«ãã (day10g)
å¾æ¥ã®å®è£
ã§ã¯ Window
ã«ããå®è£
ããã¦ãããã¹ã¦ã®è¦ç´ ããã©ãã°å¯è½ã ã£ããããã³ã³ã½ã¼ã«ããã¹ã¯ãããã®èæ¯ããã©ãã°å¯è½ã«ãªã£ã¦ãã¾ã£ã¦ãã¾ããã
main_window
ã ããã©ãã°ã§ããããã«æ¹é ãã¾ãã
Layer
ã« draggable
ã¨ããã¡ã³ãã¼ã追å ããå½è©²ã¡ã³ãã true
ã®å ´åã®ã¿ãã©ãã°å¦çãå®è¡ããããã«ãã¾ãã
å
ã®ç¯ã§ layer
ã® CoTask
ã«ãã©ãã°é¢ä¿ã®å¦çã移åãããã¨ã§ãç°¡åã«å®è£
ãããã¨ãã§ãã¾ããã
(mouse
ã® CoTask
ã§åã¬ã¤ã¤ã®ãã©ãã°å¯å¦ãåå¾ãããã¨ããã¨ãlayer
ã® CoTask
ã¨ã®ã¡ãã»ã¼ã¸ããã¨ããå¢ããå¿
è¦ããããã)
第11ç«
Local ACPI ã«ããã¿ã¤ãã¼ãå®è£ ããç« ã§ãã
ã½ã¼ã¹ã³ã¼ãã®æ´ç (day11a)
ã½ã¼ã¹ã³ã¼ãã®ã¢ã¸ã¥ã¼ã«æ§é ãæ´çããç¯ã§ãã Rustçã§ã¯æåããã¢ã¸ã¥ã¼ã«æ§é ãæ´çãã¦ãããããç¹ã«ä½ãè¡ã£ã¦ãã¾ããã
ã¿ã¤ãã¼å²ã込㿠(day11b)
Local ACPI ã«ããã¿ã¤ãã¼å²ãè¾¼ã¿ãå®è£ ãã¾ãã
å®è£
㯠xHC ã®å²ãè¾¼ã¿ã¨ã»ã¨ãã©åãã§ãããå²ãè¾¼ã¿ã®çºçæç¡ã ããåããã°è¯ã xHC ã¨ç°ãªããå²ãè¾¼ã¿ãçºçããåæ°ãéè¦ãªãããå²ãè¾¼ã¿çºçåæ°ã AtomicU64
ã§ã«ã¦ã³ãããããã«ãã¦ãã¾ãã
ã¿ã¤ãã¼ééã®ç縮ã¨ã¿ã¤ãã¼ããã¼ã¸ã£ã¼ã®è¿½å (day11c)
ã¿ã¤ãã¼ã®è¨å®ã«ããå²ãè¾¼ã¿ééãç縮ããã®ã¨ãã¿ã¤ãã¼ã管çãã TimerManager
ã追å ãã¾ãã
è¤æ°ã®ã¿ã¤ãã¼ã¸å¯¾å¿ãã (day11d)
ããã°ã©ã ã®è¤æ°ç®æã§åæã«ã¿ã¤ãã¼ã«ããå¾ ã¡åãããã§ããããã«ãã¾ãã
åã®ç¯ã§è¿½å ãã TimerManager
ã«ãã¿ã¤ãã¼ã®ç»é²ã¨ã¿ã¤ã ã¢ã¦ãã®éç¥æ©è½ãå®è£
ãã¾ãã
timer
ã® CoTask
ã§ã¯ ACPI ã¿ã¤ãã¼ã®å²ãè¾¼ã¿ã¨ä»ã® CoTask
ããã®ã¿ã¤ãã¼ç»é²ä¾é ¼ã¨ããç°ãªããã¥ã¼ããã®äºç¨®é¡ã®ã¤ãã³ããå¦çããªãã¨ãããªãããã futures_util::select_biased
ãã¯ããå©ç¨ãã¦ãã¾ãã select
ãã¯ã㯠std
ãå¿
è¦ã§ããã select_biased
㯠std
ä¸è¦ãªã®ã§ããªã¼ã¹ã¿ã³ãã£ã³ã°ç°å¢ã§ãå©ç¨ã§ãã¾ãã
ãªããã¿ã¤ãã¼å²ãè¾¼ã¿ã§ä½¿ããã¨æãåçã« CoTask
ã spawn
ã§ããããã«ããä»çµã¿ã Executor
ã«è¿½å ãã¾ããããçµå±ä½¿ãã¾ããã§ããã
ä»å¾å©ç¨åºæ¥ãå ´é¢ããããã¨æããå®è£
ã¯ãã®ã¾ã¾ã«ãã¦ãã¾ãã
RSDP ãåå¾ãã (day11e)
æ£ç¢ºãªæå»ãåãã ACPI PM ã¿ã¤ãã¼ãå©ç¨ããããã®æºåã®ç¯ã§ãã
Rust å®è£
ã§å©ç¨ãã¦ãããã¼ããã¼ãã¼ã§ãã bootloader
ã¯ã¬ã¼ãã§ã¯ãèµ·åæã®ãã©ã¡ã¼ã¿ã¨ã㦠RSDP ã¸ã®ãã¤ã³ã¿ã渡ããããããã«ã¼ãã«å´ã®å®è£
ã¯ç¹ã«é£ãããã¨ã¯ããã¾ããã§ãã (ä¾ã«ãã£ã¦ RSDP ã®ç©çã¢ãã¬ã¹ãä»®æ³ã¢ãã¬ã¹ã«ãããã³ã°ããã¦ããªãã£ãããããã¼ã¸ãã¼ãã«ã®æ¸ãæãã¯è¡ã£ã¦ãã¾ãã)ã
åé¡ããã£ãã®ã¯ bootloader
å´ã®å®è£
ã§ããã
å
·ä½çã«ã¯ã ACPI v1 㨠v2 ã®ä¸¡æ¹ã® RSDP ãåå¨ããå ´åã«ã ACPI v1 å´ã® RSDP ãã«ã¼ãã«ã¸æ¸¡ãå ´åãããããã§ãã
ããã¯ãUEFI ã®ãã¼ããã¼ãã¼å®è£
㧠ACPI v1 㨠ACPI v2 ã® RSDP ã®ãã¡ãå
ã«è¦ã¤ãã£ãæ¹ãã«ã¼ãã«ã¸æ¸¡ãããã«ãªã£ã¦ããããã§ãã
çè ã®QEMUç°å¢ã§ã¯å¿ ã ACPI v1 ã® RSDP ã渡ãããããã§ããã ACPI PM ã¿ã¤ãã¼å©ç¨ã®ããã«ã¯ ACPI v2 ã® RSDP ãå¿ è¦ãªã®ã§ããã§ã¯å°ã£ã¦ãã¾ãã¾ãã
ã²ã¨ã¾ãã bootloader
ã«ããããå½ã¦ã ACPI v1 ã® RSDP ã¯ç¡è¦ããããã«ãã¾ããã
ã¾ãã bootloader
ã® GitHub ãªãã¸ããªã« issue ãç«ã¦ã¾ããã
ä½è ã®æ¹ã«ãåå¿é ããã®ã§ããã®ãã¡è§£æ±ºãããã¨ãããªã¼ã
第12ç«
ACPI PM ã¿ã¤ãã使ããããã«ããã®ã¨ããã¼ãã¼ãããã®å ¥åã«å¯¾å¿ããç« ã§ãã
FADT ãæ¤ç´¢ãã (day12a)
åã®ç¯ã§æ¤ç´¢ãã RSDP ããã©ã£ã¦ XSDT ãåå¾ãããããæ´ã« FADT ãæ¤ç´¢ããã¨ããç¯ã§ãã
ã ããã C++ å®è£ ã¨åãã§ããã Rust ã®ã¤ãã¬ã¼ã¿ã¼ã§ã¯ã¡ã½ãããã§ã¼ã³ã§æ¤ç´¢å¦çãç°¡æ½ã«æ¸ããã®ãè¯ãã§ããã
ACPI PM ã¿ã¤ãã¼ã«ããã¿ã¤ãã¼ééãè£æ£ãã (day12b)
æ£ç¢ºãªæéãåããã¿ã¤ãã¼ã§ãã ACPI PM ã¿ã¤ãã¼ã«ãããå¨æãä¸æãªã¿ã¤ãã¼ã§ãã Local APIC ã¿ã¤ãã¼ã®å¨æã測å®ãã¾ãã
ãããã¾ã C++ å®è£ ã¨åãã§ãã ä½è«ã§ãããçè ç°å¢ã ã¨ã©ããæéãæ£ããè¨ãã¦ããªããããªæ°ããã¦ãã¾ãã 1ç§ééã®ã¯ããã3ç§ééãããã«ãªã£ã¦ãã¾ãã çè 㯠WSL2 ä¸ã§ QEMU ãåä½ããã¦ããã®ã§ããã WSL2 ã§ã¯ (ã¾ã ) Nested VM ããµãã¼ãããã¦ããªãããã QEMU ã®åä½ãé ããã¨ãåå ãªã®ã§ããããã
ãã¼ãã¼ãããã®å ¥åãå¦çãã (day12c)
ãã¼å ¥åãåãåã£ã¦ç»é¢ã«åºåããç¯ã§ãã
C++ å®è£ ã¨åãã§ç¹ã«æ¸ããã¨ãããã¾ãã...
修飾ãã¼ãå¦çãã (day12d)
Ctrl ã Shift ãªã©ã®ä¿®é£¾ãã¼ãå¦çã§ããããã«ãã¾ãã
C++ ã¨åãã§ããã
ããã¹ãããã¯ã¹ã表示ãã (day12e)
ããã¹ãããã¯ã¹ãå«ãã¦ã¤ã³ãã¦ãä½æãããã¼å ¥åã«å¿ãã¦ããã¹ãããã¯ã¹å ã«æåã表示ãã¾ãã
ããã¹ãããã¯ã¹ã®ã¦ã¤ã³ãã¦ãç¬ç«ãã CoTask
ã¨ãã¦å®è£
ãã¦ãã¾ãã
ã¾ãããã¼ãã¼ãå
¥åãå¦çãã keyboard
CoTask
ãã㯠mpsc::Sender
çµç±ã§ãã¼å
¥åã¤ãã³ããããã¹ãããã¯ã¹ã® CoTask
ã¸ç´æ¥éä¿¡ããããã«ãã¦ãã¾ãã
å°æ¥çã«ã¯éä¿¡å
CoTask
ãåçã«åãæ¿ããå¦çãå¿
è¦ã«ãªãã§ãããããã¨ããããã¯ãã®ãããªç°¡åãªå®è£
ã«ãã¦ããã¾ãã
ç¹æ» ããã«ã¼ã½ã«ãæç»ãã (day12f)
ããã¹ãããã¯ã¹ã«å ¥åä½ç½®ã示ãã«ã¼ã½ã«ãæç»ãã¾ãã
0.5ç§ãã¨ã«ã¿ã¤ãã¼ã¤ãã³ããçºçãããã¤ãã³ãå¥æ©ãã¨ã«ã«ã¼ã½ã«ã®æç»ãåé¤ãç¹°ãè¿ãã¾ãã
å®æçã«å®è¡ãããã¿ã¤ãã¼ã§ãã timer::interval
ã追å ããç°¡åã«å©ç¨ã§ããããã«ãã¦ãã¾ãã
ã¾ã¨ã
C++ å®è£ ã¨ã ãããåãã§æ¸ããã¨ãã ãã ãç¡ããªã£ã¦ãã¾ããããã¡ã¢ä»£ããã«ããã°è¨äºã¯æ®ãã¦ããããã¨ã¯æã£ã¦ãã¾ãã
æ¬¡ç« ã¯ã¤ãã«ããªã¨ã³ããã£ããã«ãã¿ã¹ã¯ã®å®è£ ã§ããRust ã§ãã¾ãå®è£ ã§ããã®ãã楽ãã¿ã§ããã
- ã·ãªã¼ãºæåã®è¨äº: 「ゼロからのOS自作入門」を Rust でやる (第1章~第4章) - gifnksmの雑多なメモ
- åå: 「ゼロからのOS自作入門」を Rust でやる (第9章) - gifnksmの雑多なメモ
- 次å: 「ゼロからのOS自作入門」を Rust でやる (第13章) - gifnksmの雑多なメモ
- é¢é£è¨äºä¸è¦§: ゼロからのOS自作入門 カテゴリーの記事一覧 - gifnksmの雑多なメモ