OS Developer として Rustを使ってみる/using-rust-for-os-developer

OS Developer として Rustを使ってみる/using-rust-for-os-developer

Rust入門者の集い (2016.11.21)でLT発表を行った際に使った資料です。

Ee6254efe6c4bc4c08967c11d4939245?s=128

kotetu (kotetuco)

November 21, 2016
Tweet

Transcript

  1. OS Developer ͱͯ͠ RustΛ࢖ͬͯΈΔ Rustೖ໳ऀͷू͍ (2016.11.21) @kotetu

  2. ܀ࢁ ప (@kotetu) • Github : kotetuco • SansanגࣜձࣾͰiOSΞϓϦ࡞ͬͯ·͢ •

    ໊ࢗ؅ཧΞϓϦͷձࣾ • ʮͦΕɺૣ͘ݴͬͯΑ͒ʯͷCMͰ͓ͳ͡Έ
  3. ͔͜͜Β͸ iOS OS ͷ࿩Ͱ͢ɻ

  4. ࣗ࡞OS • ֶੜ࣌୅ʹগ͠΍͍ͬͯͨ • ʮ30೔ͰͰ͖ΔOSࣗ࡞ೖ໳ʯ(໊ஶ) Ͱݴ͏ͱ 23೔໨͘Β͍·Ͱ

  5. Rustͱͷग़ձ͍ • OS͕ॻ͚Δݴޠ͕͋Δͧ • SwiftͬΆ͍ॻ͖ํ͕ग़དྷΔͬΆ͍ͧɹɹɹɹ (ྺ࢙తʹ͸Rustͷํ͕ઌͰ͚͢Ͳɾɾ) • ੲॻ͍͍ͯͨOSΛRustͰॻ͖௚ͯ͠ΈΔʁ

  6. ͱ͍͏Θ͚Ͱɺ࢝ΊͯΈͨ • ructiss • https://github.com/kotetuco/ructiss • OSͱͯ͠·ͩԿ΋Ͱ͖͍ͯͳ͍ (ٽ • Rust͸΄ͱΜͲॻ͍͍ͯͳ͍

  7. ը໘ΛനృΓͰ͖ͳ͍ (ٽ

  8. ։ൃ؀ڥ͸ʁ

  9. DockerfileίϯςφԽ͠·ͨ͠ • rust-baremetal • https://github.com/kotetuco/rust- baremetal • ΤϛϡϨʔλʹ͍ͭͯ͸ผ్QEMUͳͲΛ ༻ҙ͍ͯͩ͘͠͞

  10. RustͰOSΛॻ͘ϝϦοτ(1/2) • ҆શੑɺϝϞϦ؅ཧ • ඪ४͕Πϛϡʔλϒϧͳͷ͸ྑ͍ͳ • “unsafe”ϒϩοΫͰΞϯηʔϑίʔυΛݶఆ • ιϑτ΢ΣΞͷ҆શੑ͕ٻΊΒΕΔ෼໺ʹ ࢖͑ΔͷͰ͸ʁ

  11. RustͰOSΛॻ͘ϝϦοτ(2/2) • OS meets ؔ਺ܕݴޠ (࢖ͬͯΈ͍ͨ) • OS meets Reactive

    Programing ɹɹɹɹ (RxRust࢖ͬͯΈ͍ͨ) • Cargo(ϏϧυɾύοέʔδϚωʔδϟ)ͷଘࡏ • C/C++ͱͷI/F
  12. RustͰOSΛॻ͘ࡍͷཹҙ఺ • NightlyϏϧυͰ͔͠։ൃͰ͖ͳ͍ • IntelΞʔΩςΫνϟҎ֎ͷϓϥοτϑΥʔϜ ʹ͍ͭͯ͸֤ίϛϡχςΟʹґଘ

  13. ϓϥοτϑΥʔϜαϙʔτঢ়گ (Getting StartedΑΓ) • 1ڃ(Ϗϧυग़དྷ͔ͭಈ͘͜ͱΛอূ͢Δ) • IntelΞʔΩςΫνϟ(32/64bit, Win/Mac/Linux) • ARMܥ΍Android,

    iOSͳͲ͸3ڃ (αϙʔτର ৅͕ͩɺެࣜͰมߋ؅ཧ͸ߦ͍ͬͯͳ͍)
  14. ·ͱΊ • ͜Ε·ͰC/C++͡Όͳ͍ͱॻ͚ͳ͔ͬͨ෼໺ ʹ͍ͭͯɺ༗ྗͳผͳબ୒ࢶ͕Ͱ͖ͨ • ίϛϡχςΟΛ੝Γ্͍͛ͯͬͯɺC/C++Έ ͍ͨʹ༷ʑͳ෼໺Ͱ࢖ΘΕͯ΄͍͠ͳ

  15. ͓·͚ɿനృΓࣦഊίʔυ(ൈਮ) fn write_mem8(addr:u32, data:u8) { unsafe { asm!("mov BYTE PTR

    [$0], $1" : : "r"(addr), "r"(data) : : "intel"); } } pub extern fn init_os() { let vram_address = 0x000a0000; for offset in 0x00000000..0x00010000 { let vram: *mut u8 = 0x000a0000 as *mut u8; write_mem8(vram_address + offset, 0x0f); } }
  16. ༨ஊɿࣗ࡞OSͷํͷ࿩ʹ͍ͭͯ • ʮࣗ࡞OS΋͘΋͘ձʯʹࢀՃ͍ͯ͠·͢ • ࣍ճ͸ 11/26(౔) ։࠵ • https://atnd.org/events/82288