How to rewrite the OS using C by strong type How to rewrite the OS using C by strong type How to rewrite the OS using C by strong type How to rewrite the OS using C by strong type How to rewrite the OS using C by strong type Metasepi Project / Kiwamu Okabe Metasepi Project / Kiwamu Okabe Metasepi Project / Kiwamu Okabe Metasepi Project / Kiwamu Okabe Metasepi Project / Kiwamu Okabe
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
☆ Organizer of Metasepi Project☆ Organizer of Metasepi Project☆ Organizer of Metasepi Project☆ Organizer of Metasepi Project☆ Organizer of Metasepi Project
☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler☆ A developer of Ajhc Haskell compiler
☆ A Debian Maintainer☆ A Debian Maintainer☆ A Debian Maintainer☆ A Debian Maintainer☆ A Debian Maintainer
☆ 10 years' experience in developing OS using NetBSD☆ 10 years' experience in developing OS using NetBSD☆ 10 years' experience in developing OS using NetBSD☆ 10 years' experience in developing OS using NetBSD☆ 10 years' experience in developing OS using NetBSD
AgendaAgendaAgendaAgendaAgenda
☆ [1] Problems of OS using C☆ [1] Problems of OS using C☆ [1] Problems of OS using C☆ [1] Problems of OS using C☆ [1] Problems of OS using C
☆ [2] Type safety☆ [2] Type safety☆ [2] Type safety☆ [2] Type safety☆ [2] Type safety
☆ [3] Existing OS using strong type☆ [3] Existing OS using strong type☆ [3] Existing OS using strong type☆ [3] Existing OS using strong type☆ [3] Existing OS using strong type
[1] Problems of OS using C[1] Problems of OS using C[1] Problems of OS using C[1] Problems of OS using C[1] Problems of OS using C
☆ Most OS uses C language☆ Most OS uses C language☆ Most OS uses C language☆ Most OS uses C language☆ Most OS uses C language
☆ C is good for system programming☆ C is good for system programming☆ C is good for system programming☆ C is good for system programming☆ C is good for system programming
☆ But C occurs many problems☆ But C occurs many problems☆ But C occurs many problems☆ But C occurs many problems☆ But C occurs many problems
☆ Pointer to array doesn't know the length☆ Pointer to array doesn't know the length☆ Pointer to array doesn't know the length☆ Pointer to array doesn't know the length☆ Pointer to array doesn't know the length
Page fault in kernelPage fault in kernelPage fault in kernelPage fault in kernelPage fault in kernel
☆ Page fault in user space => SEGV☆ Page fault in user space => SEGV☆ Page fault in user space => SEGV☆ Page fault in user space => SEGV☆ Page fault in user space => SEGV
☆ Page fault in kernel space => Halt!☆ Page fault in kernel space => Halt!☆ Page fault in kernel space => Halt!☆ Page fault in kernel space => Halt!☆ Page fault in kernel space => Halt!
Weak typeWeak typeWeak typeWeak typeWeak type
☆ Great use of (void *) type☆ Great use of (void *) type☆ Great use of (void *) type☆ Great use of (void *) type☆ Great use of (void *) type
☆ No choice but to use weak type for flexibility☆ No choice but to use weak type for flexibility☆ No choice but to use weak type for flexibility☆ No choice but to use weak type for flexibility☆ No choice but to use weak type for flexibility
[2] Type safety[2] Type safety[2] Type safety[2] Type safety[2] Type safety
☆ Get less runtime errors☆ Get less runtime errors☆ Get less runtime errors☆ Get less runtime errors☆ Get less runtime errors
Strong type avoids buffer overrun.Strong type avoids buffer overrun.Strong type avoids buffer overrun.Strong type avoids buffer overrun.Strong type avoids buffer overrun.
Avoid page fault in kernelAvoid page fault in kernelAvoid page fault in kernelAvoid page fault in kernelAvoid page fault in kernel
Only touch the area constructed.Only touch the area constructed.Only touch the area constructed.Only touch the area constructed.Only touch the area constructed.
Flexibility without weak typeFlexibility without weak typeFlexibility without weak typeFlexibility without weak typeFlexibility without weak type
☆ Type class☆ Type class☆ Type class☆ Type class☆ Type classclass Functor f where fmap :: (a -> b) -> f a -> f binstance Functor [] where fmap f (x:xs) = f x : fmap f xs fmap f [] = []instance Functor Maybe where fmap _ Nothing = Nothing fmap f (Just x) = Just (f x)
class Functor f where fmap :: (a -> b) -> f a -> f binstance Functor [] where fmap f (x:xs) = f x : fmap f xs fmap f [] = []instance Functor Maybe where fmap _ Nothing = Nothing fmap f (Just x) = Just (f x)
class Functor f where fmap :: (a -> b) -> f a -> f binstance Functor [] where fmap f (x:xs) = f x : fmap f xs fmap f [] = []instance Functor Maybe where fmap _ Nothing = Nothing fmap f (Just x) = Just (f x)
class Functor f where fmap :: (a -> b) -> f a -> f binstance Functor [] where fmap f (x:xs) = f x : fmap f xs fmap f [] = []instance Functor Maybe where fmap _ Nothing = Nothing fmap f (Just x) = Just (f x)
class Functor f where fmap :: (a -> b) -> f a -> f binstance Functor [] where
fmap f (x:xs) = f x : fmap f xsfmap f [] = []
instance Functor Maybe wherefmap _ Nothing = Nothingfmap f (Just x) = Just (f x)
☆ Type inference☆ Type inference☆ Type inference☆ Type inference☆ Type inference
☆ IoT:Internet of Things☆ IoT:Internet of Things☆ IoT:Internet of Things☆ IoT:Internet of Things☆ IoT:Internet of Things
☆ Poor hardware, and Rich feature☆ Poor hardware, and Rich feature☆ Poor hardware, and Rich feature☆ Poor hardware, and Rich feature☆ Poor hardware, and Rich feature
☆ Many custom requests shower kernel☆ Many custom requests shower kernel☆ Many custom requests shower kernel☆ Many custom requests shower kernel☆ Many custom requests shower kernel
☆ Strong type is needed by kernel rather than application on user space☆ Strong type is needed by kernel rather than application on user space☆ Strong type is needed by kernel rather than application on user space☆ Strong type is needed by kernel rather than application on user space☆ Strong type is needed by kernel rather than application on user space
[3] Existing OS using strong type[3] Existing OS using strong type[3] Existing OS using strong type[3] Existing OS using strong type[3] Existing OS using strong type
Alreadly we have.Alreadly we have.Alreadly we have.Alreadly we have.Alreadly we have.
Rewrite kernel using C with strong type by little and little.Rewrite kernel using C with strong type by little and little.Rewrite kernel using C with strong type by little and little.Rewrite kernel using C with strong type by little and little.Rewrite kernel using C with strong type by little and little.
UNIX like OS needs reentrantUNIX like OS needs reentrantUNIX like OS needs reentrantUNIX like OS needs reentrantUNIX like OS needs reentrant
Strong type OS uses polling intrStrong type OS uses polling intrStrong type OS uses polling intrStrong type OS uses polling intrStrong type OS uses polling intr
Context can run without lock.Context can run without lock.Context can run without lock.Context can run without lock.Context can run without lock.
[5] Demo[5] Demo[5] Demo[5] Demo[5] Demo
The proof of the pudding is in the eating.The proof of the pudding is in the eating.The proof of the pudding is in the eating.The proof of the pudding is in the eating.The proof of the pudding is in the eating.
MCU app without OS #1MCU app without OS #1MCU app without OS #1MCU app without OS #1MCU app without OS #1https://github.com/ajhc/demo-cortex-m3https://github.com/ajhc/demo-cortex-m3https://github.com/ajhc/demo-cortex-m3https://github.com/ajhc/demo-cortex-m3https://github.com/ajhc/demo-cortex-m3
MCU app without OS #2MCU app without OS #2MCU app without OS #2MCU app without OS #2MCU app without OS #2
MCU app with OSMCU app with OSMCU app with OSMCU app with OSMCU app with OShttps://github.com/ajhc/demo-cortex-m3https://github.com/ajhc/demo-cortex-m3https://github.com/ajhc/demo-cortex-m3https://github.com/ajhc/demo-cortex-m3https://github.com/ajhc/demo-cortex-m3
[6] Case study of Snatch[6] Case study of Snatch[6] Case study of Snatch[6] Case study of Snatch[6] Case study of Snatch
We found some idioms that are useful to rewrite C language with Haskell.We found some idioms that are useful to rewrite C language with Haskell.We found some idioms that are useful to rewrite C language with Haskell.We found some idioms that are useful to rewrite C language with Haskell.We found some idioms that are useful to rewrite C language with Haskell.
C and Haskell call with each other.C and Haskell call with each other.C and Haskell call with each other.C and Haskell call with each other.C and Haskell call with each other.
Haskell can read/write memory directly.Haskell can read/write memory directly.Haskell can read/write memory directly.Haskell can read/write memory directly.Haskell can read/write memory directly.
Read structs chained with pointer.Read structs chained with pointer.Read structs chained with pointer.Read structs chained with pointer.Read structs chained with pointer.
Directly insert the text following const.Directly insert the text following const.Directly insert the text following const.Directly insert the text following const.Directly insert the text following const.