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. w ͍ΘΏΔී௨ʹ࢖͏04 w (6*Λ࣋ͬͯͨΓ͢Δ w αʔόʹ࢖͏04 w (6*͸࣋ͬͯͳ͍͜ͱ͕ ଟ͍ w

    1$Ҏ֎ͷػցͰಈ͘04 w ϦΞϧλΠϜੑ͕͋ͬͨ Γͳ͔ͬͨΓ 04ͷछྨ σεΫτοϓ04 αʔό04 ૊ࠐΈ04 ը໘ඳը͕େมͦ͏ʜɻ ϓϩηε؅ཧͱ͔Λਅ໘ ໨ʹ΍Δͱେมͦ͏ʜɻ ͍Ζ͍ΖಠಛͰͭΒ͍ɻ ˞ݸਓͷݟղͰ͢ ˠ΋ͬͱखܰͳΰʔϧ͕΄͍͠ 
  2. ୯ҰΞϓϦέʔγϣϯ༻04 w 6OJLFSOFM<> &YPLFSOFM<>ͳͲͱݺ͹ΕΔ w 7.্Ͱಈ࡞ͤ͞Δ͜ͱ͕લఏ w ௨ৗͷ04ʹର͢Δར఺ w ༨ܭͳ΋ͷ͕ͳ͍ͷͰɺΑΓηΩϡΞ

    w ༨෼ͳϑΝΠεγεςϜ΍ωοτϫʔΫελοΫ͕ͳ͍ͷͰɺ ύϑΥʔϚϯε͕͍͍ w 04શମʹ౉ͬͨ࠷దԽΛ͔͚ΕΔ
 <>6OJLFSOFMTMJCSBSZPQFSBUJOHTZTUFNTGPSUIFDMPVE IUUQEMBDNPSHDJUBUJPODGN JE
 <>&YPLFSOFMBOPQFSBUJOHTZTUFNBSDIJUFDUVSFGPSBQQMJDBUJPOMFWFMSFTPVSDFNBOBHFNFOUIUUQEMBDNPSHDJUBUJPODGN JE 
  3. .JSBHFͷ࢓૊Έ 9FO .JOJ04 .JOJ04 0UIFS04 0$BNM ϥϯλΠϜ ()$ ϥϯλΠϜ 0$BNM

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

    MJCD΍5$1*1ελοΫ΋ಈ࡞͢Δ ˠ͜Ε૬౰ͷ΋ͷΛؔ਺ܕݴޠͰॻ͘ͷ͕໨ඪ 
  5. BKID BGPSLPGKID w .FUBTFQJ͕GPSLͨ͠)BTLFMMίϯύΠϥ w ಛ௃ w ()$͡Όͳ͍ w )BTLFMMΛίϯύΠϧͯ͠$Λੜ੒͢Δ

    w ϥϯλΠϜ͕ίϯύΫτґଘ͢Δ104*9"1*͕গͳ ͍ w $ͱ૬ޓݺͼग़͕͠؆୯ʹͰ͖Δ 
  6. ߏ଄ମ  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ଆ 
  7. ߏ଄ମ  struct { time_t now; // Ͳ͔͜Ͱtypedef͞Εͯͯܕ͕Θ͔Βͳ͍ struct {

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

    offset; } Section; uint32_t get_id(struct Section* p) { ... } uint32_t get_offset(struct Section* p) { ... } 
  9. *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ͬΆ͘ͳ͍