hckr83 wrote:
Well, I was thinking about how to make an OS more portable, and well....most parts of an OS just can't be made portable(even with a layer) but the actual OS kernel possibly could..
There are some parts of any OS that are impossible to make portable -- you just have to implement them for each architecture. It's all really low-level stuff though (interrupt handling stubs, syscall dispatching, low-level I/O for drivers, managing the MMU structures). Pretty much everything else can be abstracted and made portable.
Have you looked at Linux or any other OS to see how they do it? This is not a new idea...
Quote:
really, I think some assumptions should be made, such as an MMU is present
For OSes that use hardware memory protection, this is definitely true. For example, Linux makes certain assumptions about an MMU being present, and supporting certain address space sizes, etc.
Quote:
But basically make something to seperate things like task switching, memory protection, and other things like that on the CPU(or common thing on the mobo)
What do you mean by "separate things" exactly? Keep these things separate from each other, or for each thing, to separate its architecture-specific and architecture-independent parts?
Pretty much every OS I know of has a hardware abstraction layer "HAL" that does more or less what you're proposing.
os64dev wrote:
Well it can be done rather easily if you use the bridge, abstract factory and strategy design pattern.
In theory, yes.
In practice, these patterns often rely on OO language features like polymorphism to work, which in C++ is inconvenient unless you allocate objects on the heap, which is not something you want to be doing in the lowest-level parts of the kernel.
Sometimes you can implement these design patterns "statically" in a way that would be safe to use in low-level code. For example, you can use templates to implement a static version of the strategy pattern, where the strategy is a template parameter and each instantiation uses a different concrete strategy.
It's quite misleading to say that using these patterns makes it easy though. It just gives you a mental framework that makes it easy to
understand what you have to do. Actually doing it (figuring out how to abstract hardware) is always challenging.
I'm a bit puzzled why this is being discussed as though it is a new and somehow novel idea... Try looking around at some other OSes to see how they are designed for portability. Sometimes you'll find that with microkernels in particular, the whole kernel is architecture-specific so that everything else can be portable. Other times almost the entire OS is portable.