The device library contains some function which can simplify writing device drivers, and more importantly abstracts operating system specific details so that drivers can be portable between different operating systems. This is most important for the device drivers that we provide for you such as the serial and network drivers.
You may wish to use this library directly when writing your clock driver. Depending on the design of your operating system you may wish to modify libdevice. This library depends on the structure and functions you provide in SOS.
The function get_pinnable_memory
is used by device
drivers to allocate memory that can be accessed by the DMA
controller. The current implementation uses the
frame_alloc
function that is implemented in
frames.c
. If you change the interface to your frame
table you should ensure that you also change
get_pinnable_memory
. This also means that if your
frame_alloc
doesn't work then you will probably break
the device drivers.
The function map_physical
is used by device drivers
to map the physical address space (where device registers are
mapped) into the driver's address space. For you purposes, the
first argument, host
can be passed as
NULL
.
The other aspect that impacts on you is the handling of
interrupts. When a device driver needs a CPU interrupt it will
call register_cpu_interrupt_handler
, to which it
passes a handle (which in SOS, is just NULL), the irq
it wants to receive notifications from, and a pointer to a
function
which should be called whenever the given
interrupt occurs. The mapping from irq to handler function is
stored in the irq_handlers
array.
The current implementation sets the root thread as the interrupt
handler for any registered interrupts. You may wish to change this
implementation so that each interrupt is handled by a different
thread. The implementation of SOS we have provided to you calls the
function irq_handler
whenever an interrupt occurs. This
function decodes which interrupt occurred, and calls the registered
function. If you change this implementation you will need to ensure
that the correct function is called when an interrupt occurs.