blob: 5cdc41483e65a40977771f9906d878f046298e1a [file] [log] [blame]
swissChilie00e88a2021-05-30 17:54:26 -07001Architecture
2============
3
4This document seeks to provide a brief overview of Bluejay architecture. This
5should be a good starting point for understanding the code.
6
7Bluejay is exclusively a multiboot kernel, it neither provides nor supports
8alternative bootloaders.
9
10The bootloader (probably GRUB) will initially run the code in ``boot.s``. This
11is where it all begins. This code sets up segmentation and paging and maps the
12higher-half of virtual memory (everything above ``0xC0000000``) to the kernel.
13At first it only maps 8 megabytes, more memory can be mapped on request.
14
15After moving to high memory the kernel jumps to C code and enters ``kmain`` in
16``main.c``. This is the highest level procedure in the kernel, which sets up
17kernel services and drivers one at a time.
18
19This includes VGA, keyboard, and PCI drivers, as well as paging and preemptive
20multi tasking.
21
22Multi tasking
23-------------
24
25Multi tasking is handled by code in ``task.c``. It is first initialized in
26``init_tasks``, which sets up the initial task. Once this is called kernel
27threads can be spawned at will.
28
29Every clock tick an interrupt is triggered (see ``clock.c`` for timing) which
30causes a task switch to occur. Bluejay uses a simple round-robin scheduler, and
31there is no way for tasks to voluntarily give up their processing time (even in
32the case of blocking IO operations). ``task.c`` contains the implementation of
33the scheduler.
34
35Drivers
36-------
37
swissChili1b839222021-06-03 13:54:40 -070038So far drivers must be written either using plain ``in`` and ``out``
39instructions or on top of the existing PCI driver.
40
41PCI Device Drivers
42~~~~~~~~~~~~~~~~~~
43
44PCI device drivers must register a ``struct pci_device_driver`` in order to
swissChilicaa24782021-07-19 14:29:58 -070045interface with a certain device (or class of devices). See
46``include/kernel/dri/pci/pci.h`` for details.
swissChili1b839222021-06-03 13:54:40 -070047
48A PCI device driver must pass an instance of this structure to
49``pci_register_device_driver`` (in ``include/kernel/dri/pci/pci.h``. If
50``supports`` returns true, (for example, if the class and subclass of the
51``struct pci_device`` are supported by teh driver) ``init`` will be called. At
52this point the driver may do whatever it wishes with the PCI device, although
53all blocking operations should be done in another thread (using ``spawn_thread``
54in ``include/kernel/task.h`` for example).