More about the NitrOS-9 Kernel file

From NitrOS-9
Jump to: navigation, search

The NitrOS-9 Kernel file contains the entry point for the boot process. Traditionally, it is stored on Track 34 of the boot disk. This imposes a file-size limit on the Kernel file, which in turn results in a 2-stage boot process (the second stage uses the Boot file). See also The_NitrOS-9_Boot_Process_Explained and More_about_the_NitrOS-9_Boot_file

The Kernel file is created by concatenating multiple binary modules.

This works because each NitrOS-9 module is relocatable code and because there is a header on each module which allows the modules to be treated as a linked list that is searchable by module name.

Theoretically, this allows the modules to be concatenated in any order. However, there are some assumptions about module ordering for the Kernel file as a result of assumptions/simplifications made in the boot process:

  • The module REL (short for RELocate) must always be first. The bootstrap code that loads the "Track 34" branches to a fixed offset from the start of the Kernel file, corresponding the the entry point of the first module, so that first module must be REL.
  • For NitrOS-9 Level 1, the KRN must be adjacent to REL because REL computes the entry point of KRN as a fixed offset from the end of REL.
  • For NitrOS-9 Level 2, the KRN must be the last module because the end of KRN must be aligned to a specific memory address up in the $FExx address range.

A typical Kernel file for Level 1 looks like this:

KERNEL_1773     = $(MD)/rel $(MD)/krn $(MD)/krnp2 $(MD)/init $(MD)/boot_1773_6ms

A typical Kernel file for Level 2 looks like this:

KERNEL_1773	= $(MD)/rel_80 $(MD)/boot_1773_6ms $(MD)/krn

In both cases, the build process pads the Kernel file to an exact size (typically 4608, $1200 bytes) but the way that this is achieved is different for Level 1 and Level 2.

  • For Level 1, the modules are built and concatenated and then the Kernel file is padded to the required size. For example, inspect the PADROM commands in level1/coco1/bootfiles/makefile.
  • For Level 2, the REL, BOOT and KRN modules each contain padding code in the .asm source-code so that each is a specific size; once concatenated, each module starts at a fixed offset (and therefore at a fixed address once the Kernel file is loaded at address $2600). Specifically, the file sizes are:
    • REL - 304 ($130) bytes
    • BOOT - 464 ($1D0) bytes
    • KRN - 3840 ($F00) bytes

The padding can only be achieved by implementing it in each module; no module knows anything about the others, so it's not possible to, for example, lump all of the padding into KRN.

As part of the Level 2 boot process, REL copies the Kernel file from address $2600 to address $ED00. The modules are then located like this:

    $ED00 start of REL
    $EE30 start of BOOT
    $F000 start of KRN