Hi,
BMW wrote:
Has anyone got any drivers made in NASM for reading/writing to USB flash drives?? (I don't really want to spend ages writing one when there are probably plenty around)
First, normally there's a tree of device drivers and not just one. For example, you might have 4 different "USB controller" drivers (one for each different type of USB controller - UHCI, OHCI, EHCI, xHCI) that all talk to the hardware (in different ways) and provide some sort of interface for other software to use; and then you'd have drivers for a USB devices (e.g. a flash drives) that talk to the USB controller's driver using the interface that USB controllers provide. Of course this tree might be deeper - for example you might have a USB flash driver that talks to a USB hub driver that talks to another USB hub driver that talks to a USB host controller driver.
Near the top of the tree there's normally something to manage PCI buses, which is responsible detecting which PCI devices are present, managing resources that are assigned to different PCI devices, handling some power management (e.g. for PCI bridges), and starting the corresponding device drivers (and might also do other things, like handling the IOMMU if there is one and monitoring drivers and recovering/restarting them if they crash, etc). Below the drivers there's also more code - e.g. under an ethernet driver you might have several layers of code to manage things like bonding, routing, IP, TCP/UDP, etc; and under a USB flash driver you might have a piece of code to handle partitions then various pieces of code to handle different types of file systems.
The complete thing (for USB flash only) might look like this:
Code:
Device manager
|__ USB controller driver
|__ USB hub driver
|__ USB flash driver
|__ Partition manager
|__ File system code
|__ File system code
Of course it's not that simple. Typically half of this talks to the OS's virtual file system layer (for e.g. the USB flash controller might be exposed as "/dev/sdd", the partition manager might be responsible for "/dev/sdd_p0" and "/dev/sdd_p1", and the various file systems might have mount points). In addition to this, everything depends on various parts of the kernel - things like IRQ handling, memory management, communication with processes, scheduling, timers, etc.
The thing is; all of the interfaces between all of these pieces can be very different for different OS's/kernels. The kernel API's will be different, the executable file format used for drivers may be different, the way pieces communicate (messages? direct calls?) may be different, the IO model may be different (asynchronous IO with IO priorities? first come first served synchronous IO?), how resources are handled may be different (does the driver tell the device manager which resources it needs, or does the device manager tell the driver which resources it should have?), IRQ handling may be different, the way critical sections and concurrency is handled can be different, the way scheduling is done may be very different, etc.
Basically; a driver that is designed for one OS will not work in another OS. It's like taking a dog's brain and putting it into a fish - nothing will be compatible.
Cheers,
Brendan