# Anatomy of a kernel

A Dusk OS kernel needs these basic elements:

* Cold boot initialization
* HAL implementation
* The interpret loop
* Entry creation words
* A few other little words
* System Constants

## Cold boot initialization

Once the bootloader is done loading the kernel in memory, it will jump to its
first address. That's cold boot initialization.

In a "pure" system, this initialization is the equivalent of jumping to
"abort", which:

1. Initializes SYSVARS (see [doc/arch])
2. Initialises PS and RS.
3. Pushes the address of SYSVARS to PS
4. Jump to the main intepret loop

However, it's possible that the cold boot procedure needs to do some
machine-specific task, for example setting the IDT on a i386 system.

## HAL implementation

The vast majority of kernel code is HAL implementation [doc/hal]. It's the
kernel's responsibility to implement all of it.

## The interpret loop

The interpret loop is:

in< (its boot time implementation) word findentry (wnf) (wexp) (div0) stack?
findmeta findmod runword

Most of those words are specified in [doc/dict], except (wnf) (wexp) and (div0),
which are the "word not found" and "word expected" errors. They are implemented
as noops in kernels. xcomp/boot realiases them with actual implementations.

"stack? ( -- )" can be implemented as a simple noop because its actual
implementation is in xcomp/boot.

## Entry creation words

Entry creation words are:

entry metaadd code compword ]

All of those words are specified in [doc/dict].

## A few other little words

It's the kernel's responsibility to implement these words:

move []= cidx bye dup, litn (cell) parsedec

Most of those words are specified in [doc/dict], except:

(cell) ( -- n )
  When this is called, it pops its return address and pushes it to PS. Because
  the return address was popped, we never return directly to the caller, but to
  the caller's caller.

This is compiled by "create".

## SYSVARS

Additonally, the kernel must set up and initialize the SYSVARS area as described
in [doc/arch].
