Hi all,
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.
In theory, only the lowest-level code will need to be changed between platforms. The kernel doesn't allow any user-mode processes to talk to a device directly, and I figured this structure would allow the kernel an easy way to deal with complicated devices. For example, a process loader might look for a FAT16/FAT32 device and read a file. But a routine to partition/format the SD card could go direct to the "SD card" and ignore file system details. Other code might access the SPI device directly and not care what kind of device is attached to the other end of the SPI wires.
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