I've lurked this forum for quite a while, but never posted because I've not been able to find the time to start an OS project before. However, I'm making good progress on one at the minute and just wanted to see if you thought my approach to device management makes any sense.
The project is a 32-bit OS for ARM-based single board computers (like the Pi, essentially). It's monolithic and has to be recompiled for each device that I want to run it on. But, obviously, I want to define some reasonable hardware abstraction so that only the really low-level code files need to be changed when porting.
(It's being written in C (not C++) so I'm making heavy use of pointers.)
I'm not really sure how other projects handle device management (USB, on-board controllers, and integrated peripherals). But what I'd planned to do is this:
- On startup, a "device manager" builds a linked list of structs for devices that it knows about. Initially, these will be low-level drivers for integrated peripherals. E.g. an SPI driver, GPIO, USB controller etc.
- It then adds a slightly-less-low-level "device" for each integrated periph. E.g. on the Pi, there'd be a "SD card" device. Each of these devices points to functions in the previous level of devices. So the SD card code would use functions from the SPI driver. But could, in theory, be pointed at a USB device instead (for USB card readers).
- Some devices might have a third level. For example, the SD card driver might detect partitions on the card and add another set of devices for specific file systems. These drivers use functions in the SD card driver, which in turn uses the SPI drivers.
Does this sound like a reasonable approach, or have I missed something fairly important? It seems to me to be the kind of thing that other OSes might do. But there's going to be a lot of work to do to get all the devices working, so I've held of starting this until I can be at least somewhat confident that it'll actually work.
All the best,
M