Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HaskellでOSを作りたい

mzp
November 04, 2014

 HaskellでOSを作りたい

関数なんたらの集い http://connpass.com/event/8634/ で使用したスライドです。

mzp

November 04, 2014
Tweet

More Decks by mzp

Other Decks in Technology

Transcript

  1. )BTLFMMͰ04Λ࡞Γ͍ͨ !N[Q 

  2. ࣗݾ঺հ w 5XJUUFS!N[Q w 0$BNM͕޷͖Ͱ͢ɻ w )FSPLVͰಈ͘Α͏ʹͨ͠ͷͰɺΈΜͳ࢖ͬͯ͘ ͍ͩ͞ɻ w ීஈ͸໊ݹ԰Ͱɺ3BJMTϓϩάϥϚ΍ͬͯ·͢ɻ

    
  3. ؔ਺ܕݴޠͰ 04࡞Γ͍ͨͰ͢ΑͶ 

  4. w ͍ΘΏΔී௨ʹ࢖͏04 w (6*Λ࣋ͬͯͨΓ͢Δ w αʔόʹ࢖͏04 w (6*͸࣋ͬͯͳ͍͜ͱ͕ ଟ͍ w

    1$Ҏ֎ͷػցͰಈ͘04 w ϦΞϧλΠϜੑ͕͋ͬͨ Γͳ͔ͬͨΓ 04ͷछྨ σεΫτοϓ04 αʔό04 ૊ࠐΈ04 ը໘ඳը͕େมͦ͏ʜɻ ϓϩηε؅ཧͱ͔Λਅ໘ ໨ʹ΍Δͱେมͦ͏ʜɻ ͍Ζ͍ΖಠಛͰͭΒ͍ɻ ˞ݸਓͷݟղͰ͢ ˠ΋ͬͱखܰͳΰʔϧ͕΄͍͠ 
  5. 04ͱ͸Կ͔ IUUQCMPHTVQFSNPNPOHBDPNBSUJDMFTWJNWJNFNBDTNFIUNM Š7JN"EWFOU$BMFOEBS೔໨ 

  6. 04ͱͯ͠ͷWJN 

  7. 04ͱ͸Կ͔ WJN&NBDT͕ಈ͚͹04Ͱ͋Δ ͱ͍͏ΞϓϦέʔγϣϯ͕ಈ͚͹04Ͱ͋Δ )FMMP XPSME͕ಈ͚͹04Ͱ͋Δ 

  8. ୯ҰΞϓϦέʔγϣϯ༻04 w 6OJLFSOFM<> &YPLFSOFM<>ͳͲͱݺ͹ΕΔ w 7.্Ͱಈ࡞ͤ͞Δ͜ͱ͕લఏ w ௨ৗͷ04ʹର͢Δར఺ w ༨ܭͳ΋ͷ͕ͳ͍ͷͰɺΑΓηΩϡΞ

    w ༨෼ͳϑΝΠεγεςϜ΍ωοτϫʔΫελοΫ͕ͳ͍ͷͰɺ ύϑΥʔϚϯε͕͍͍ w 04શମʹ౉ͬͨ࠷దԽΛ͔͚ΕΔ
 <>6OJLFSOFMTMJCSBSZPQFSBUJOHTZTUFNTGPSUIFDMPVE IUUQEMBDNPSHDJUBUJPODGN JE
 <>&YPLFSOFMBOPQFSBUJOHTZTUFNBSDIJUFDUVSFGPSBQQMJDBUJPOMFWFMSFTPVSDFNBOBHFNFOUIUUQEMBDNPSHDJUBUJPODGN JE 
  9. ୯ҰΞϓϦέʔγϣϯ༻04ͷྫ w .JSBHFIUUQXXXPQFONJSBHFPSH 
 0$BNMͷϓϩάϥϜΛίϯύΠϧ͠ɺ9FO্Ͱಈ࡞ͤ͞ΕΔɻ
 9FO1SPKFDUͷҰ෦ɻ w 04WIUUQPTWJP
 ֤छϋΠύʔόΠβʔ্ͰΞϓϦέʔγϣϯΛ௚઀ಈ࡞ͤ͞Δɻ
 ྫSVCZ

    OPEFKT MVB NSVCZ NFNDBDIFE NZTRM SFEJT +7.  FUD w )B-7.ɾɾɾ)BTLFMM༻ w &SMBOH0O9FOɾɾɾ&SMBOH༻ 
  10. .JSBHFͷ࢓૊Έ 9FO .JOJ04 .JOJ04 0UIFS04 0$BNM ϥϯλΠϜ ()$ ϥϯλΠϜ 0$BNM

    ϓϩάϥϜ )BTLFMM ϓϩάϥϜ 9FOઐ༻ͷ04ɻ 9FOͷιʔεπϦʔʹಉࠝ ͞ΕͯΔ 
  11. .JOJ04ओͳػೳ w ίϯιʔϧͷ*0 w Ծ૝ϝϞϦ w ڠௐܕ ϊϯϓϦΤϯςΟϒ εϨου w

    MJCD΍5$1*1ελοΫ΋ಈ࡞͢Δ ˠ͜Ε૬౰ͷ΋ͷΛؔ਺ܕݴޠͰॻ͘ͷ͕໨ඪ 
  12. طଘͷࣄྫ w 'VOLIUUQIPNFHOBPSHGVOL  w 4OPXqBLF04IUUQTDPEFHPPHMFDPNQTOPXqBLFPT  w )PVTFIUUQQSPHSBNBUJDBDTQEYFEV)PVTF 

  13. .FUBTFQJ IUUQXXXNFUBTFQJPSH w A 

  14. ৄ͘͠͸ЕΧ່Ͱ w ЕΧ່ͱ͍͏ٕज़ܥಉਓࢽʹৄ͘͠ॻ͔ΕͯΔɻ w ࠓ೔࿩͢಺༰ʹ͍ۙͷ͸רͱר͋ͨΓ IUUQXXXQBSBJTPMBOHPSHJLNTN 

  15. εφον։ൃ ˠطଘͷઃܭΛྲྀ༻Ͱ͖Δ҆৺ײɺϞνϕʔγϣϯͷҡ࣋ 

  16. BKID BGPSLPGKID w .FUBTFQJ͕GPSLͨ͠)BTLFMMίϯύΠϥ w ಛ௃ w ()$͡Όͳ͍ w )BTLFMMΛίϯύΠϧͯ͠$Λੜ੒͢Δ

    w ϥϯλΠϜ͕ίϯύΫτґଘ͢Δ104*9"1*͕গͳ ͍ w $ͱ૬ޓݺͼग़͕͠؆୯ʹͰ͖Δ 
  17. ݱ࣌఺Ͱͷ੒Ռ ׬ྃ wλΠϚͷॳظԽ wϖʔδςʔϒϧͷॳظԽ wίϯιʔϧͷॳظԽ wεϨουεέδϡʔϥͷॳظԽ ະ׬ྃ wσόΠεͷॳظԽ w֤छ"1* wऴྃॲཧ

    IUUQTHJUIVCDPNN[QNJOJPTXJUIBKID 
  18. σϞ 

  19. ͭΒ͔ͬͨͱ͜Ζ 

  20. ߏ଄ମ  Data Section = Section { sectionId :: Word32

    , sectionOffset :: Word32 } deriving (Show,Eq) instance Storable Section where sizeof _ = 8 alignment _ = 4 peek ptr = do a1 <- peek (ptr `plusPtr` 0) :: IO Word32 a2 <- peek (ptr `plusPtr` 4) :: IO Word32 return $ Section a1 a2 struct { uint32_t id; uint32_t offset; } Section; $ݴޠଆ )BTLFMMଆ 
  21. ߏ଄ମ  struct { time_t now; // Ͳ͔͜Ͱtypedef͞Εͯͯܕ͕Θ͔Βͳ͍ struct {

    int x; }; // ߏ଄ମ͕ຒΊࠐ·Ε͍ͯΔ.. union { .... }; // unionͬͯͲ͏΍ͬͯHaskellͰѻ͏ΜͩΑ #ifdef LIB_C // ͑ɺ؀ڥʹΑͬͯαΠζҧ͏ͷ? int extra_fields; #end ... } Section; 
  22. ճආࡦ w ΞΫηαΛ$ݴޠͰఆٛͨ͠ w ໘౗ͳΦϑηοτܭࢉΛ$ݴޠʹ·͔ͤΕΔ struct { uint32_t id; uint32_t

    offset; } Section; uint32_t get_id(struct Section* p) { ... } uint32_t get_offset(struct Section* p) { ... } 
  23. *0Ϟφυ IUUQTQMTNVHNVHDPN)VNPS-BNCEBDBUTJU4,9LK 

  24. *0Ϟφυ w େ൒ͷؔ਺͕*0 Λฦ͢ඞཁ͕͋Δɻ setRunnable :: Ptr Thread -> IO

    () clearRunnable :: Ptr Thread -> IO () isRunnable :: Ptr Thread -> IO Bool initSched :: IO () initSched = do printk "Initialising scheduler\n" thread <- createThread funPtr setIdleThread thread initList =<< getThreadList thread return () w େ൒ͷؔ਺͕*0 Λฦ͢ඞཁ͕͋Δɻ w ͋Μ·Γ)BTLFMMͬΆ͘ͳ͍ 
  25. ίϯύΠϥͷෆ۩߹ w ૺ۰ͨ͠ෆ۩߹ w $ͷؔ਺ʹ౉ͨ͠ϙΠϯλ͕($ʹճऩ͞ΕΔ w λΠϛϯάʹΑͬͯɺར༻தͷྖҬ΋ճऩ͞ΕΔ w )BTLFMMίϯύΠϥͷ($ͷόάमਖ਼͖ͼ͍͠ w

    ஗ԆධՁͳͷͰ͍ͭॲཧ͕૸Δ͔Θ͔ΓͮΒ͍ w ͍ͭ($͞ΕΔ͔෼͔Βͳ͍ 
  26. ·ͱΊ w )BTLFMMͰ04Λॻ͜͏ͱ͠·ͨ͠ɻ w BKID࢖͑͹ͦΕͳΓʹ͍͚·͢ɻ w Ͱ΋ɺͦΕͳΓʹۤ࿑΋͋Γ·͢ɻ w )BTLFMMίϯύΠϥͷσόοά͸ͭΒ͍ɻ 

  27. ࠓޙͷ՝୊ w .FUBTFQJతʹ͸"54ʹ஫ྗ͠͸͡ΊͯΔΒ͍͠ w ઢܗܕ͕࢖͑Δ͍͢͝΍ͭ w ϥϯλΠϜ΋খ͍͞ w ؾʹͳΔ