| 1 | = MutekH startup and initializations = |
| 2 | |
| 3 | This page describes how the various parts of the kernel are initialized when the operating system starts. |
| 4 | |
| 5 | == Modular startup process == |
| 6 | |
| 7 | The MutekH statup process consists in calling many intialization functions for all components of the system. |
| 8 | Depending on the current build configuration, different modules and features are enabled at compile time. This make the |
| 9 | set of relevant initialization functions change with the current configuration. |
| 10 | |
| 11 | The initialization order of the various parts of the kernel is important because some components do |
| 12 | depend on other components which need to be initialized first. The proper order may also be different |
| 13 | depending on some configuration parameters like the target architecture. |
| 14 | |
| 15 | Rather than defining the initialization order directly, the MutekH build system generates a list of intialization |
| 16 | function calls sorted in the right order based on some expressed ordering constraints. This allows the developper of a software |
| 17 | component to insert its intialization function calls at the right time relative to intialization of other components. |
| 18 | |
| 19 | The kernel initialization stages are arranged in a hierarchical manner. Internal nodes of this intialization tree define |
| 20 | the main steps of startup process whereas leaf nodes actually define the function calls which must take place. |
| 21 | Ordering constraints are expressed along with the hierarchy using [BuildSystemDev#Initializationtokensdeclaration intialization tokens] |
| 22 | in the build system configuration files. |
| 23 | |
| 24 | == Initialization functions == |
| 25 | |
| 26 | The whole startup process is split in two main groups of intialization tokens: |
| 27 | * Intializations which take place on the bootstrap processor while other processors are waiting. |
| 28 | * Intializations which take place at the same time on all processors. |
| 29 | |
| 30 | The bootstrap processor usally starts execution in assembly code in the `cpu_boot` function. |
| 31 | It then jumps to the `mutekh_startup` function which contains function calls generated |
| 32 | by the build system for the `INIT_MUTEKH_STARTUP` initialization token. |
| 33 | |
| 34 | On multiprocessors platforms other processors enter the `mutekh_startup_smp` |
| 35 | function when instructed to do so by the bootstrap processor. This function contains function |
| 36 | calls corresponding to the `INIT_SMP` token which is actually the same as the second half of `INIT_MUTEKH_STARTUP`. |
| 37 | |
| 38 | Initialization tokens which are part of `INIT_SMP` group can call the `mutekh_startup_smp_barrier` function |
| 39 | to ensure that all processors have reached this same point in code. If an intialization must be performed |
| 40 | on a single processor in this intialization group, the result of the `cpu_isbootstrap` function must be tested. |
| 41 | |
| 42 | Startup related functions are declared in the [source:hg/mutek/include/mutek/startup.h mutek/startup.h] header file. |
| 43 | |
| 44 | == Main intialization steps == |
| 45 | |
| 46 | The first part of the startup process executed on the boostrap processor only includes the following main steps (when relevant): |
| 47 | * initialization of memory sections `.bss` and `.data`. |
| 48 | * initialization of the early output console. |
| 49 | * initialization memory and page allocators. |
| 50 | * initialization and enumeration of devices present in the platform, including processors. |
| 51 | * initialization of the associated device drivers. |
| 52 | |
| 53 | The second part of the startup process which is executed by all processors includes: |
| 54 | * initialization of each processor registers |
| 55 | * initialization of the scheduler |
| 56 | * initialization of other libraries and software components |
| 57 | * initialization of the application |
| 58 | * enter the scheduler loop |
| 59 | |
| 60 | Below is an sample herarchical view of the main intialization tokens as output by the `make listinit` command |
| 61 | with a multiprocessor build configuration (as described on the BuildSystem page). |
| 62 | |
| 63 | {{{ |
| 64 | * INIT_MUTEKH_STARTUP |
| 65 | * INIT_BOOTSTRAP |
| 66 | * INIT_MEMORY |
| 67 | * INIT_MEMORY_SECTIONS |
| 68 | * .... |
| 69 | * INIT_MUTEK_EARLY_CONSOLE |
| 70 | * .... |
| 71 | * INIT_MUTEK_MEMALLOC |
| 72 | * .... |
| 73 | * INIT_DEVICE |
| 74 | * INIT_DEVICE_TREE |
| 75 | * INIT_DEVICE_ENUM |
| 76 | * .... |
| 77 | * INIT_DEVICE_DRIVERS |
| 78 | * INIT_SMP_STARTUP_BARRIER |
| 79 | * INIT_START_CPUS |
| 80 | * .... |
| 81 | * INIT_SMP |
| 82 | * INIT_CPUS |
| 83 | * INIT_DEVICE_CPU_REGS |
| 84 | * INIT_MUTEK_FAULT_HANDLER |
| 85 | * INIT_MUTEK_SCHEDULER_INIT |
| 86 | * INIT_MUTEK_CONSOLE |
| 87 | * INIT_LIBRARIES |
| 88 | * .... |
| 89 | * INIT_APPLICATION |
| 90 | * INIT_MUTEK_SCHEDULER_START |
| 91 | }}} |
| 92 | |
| 93 | |
| 94 | The `INIT_APPLICATION` step calls the `app_start` function which must be defined in the application source code. |
| 95 | |
| 96 | Here is an example intialization function calls order retained by the build system: |
| 97 | |
| 98 | {{{ |
| 99 | INIT_MUTEKH_STARTUP (init): |
| 100 | INIT_SOCLIB_BSS soclib_bss_section_init() |
| 101 | INIT_SOCLIB_DATA soclib_data_section_init() |
| 102 | INIT_SOCLIB_EARLY_CONSOLE soclib_early_console_init() |
| 103 | INIT_SOCLIB_MEM_ALLOC soclib_mem_init() |
| 104 | INIT_DEVICE_TREE device_tree_init() |
| 105 | INIT_SOCLIB_FDT soclib_fdt_init() |
| 106 | INIT_DEVICE_DRIVERS libdevice_drivers_init() |
| 107 | INIT_SMP_STARTUP_BARRIER mutek_startup_barrier_init() |
| 108 | INIT_SOCLIB_START_CPUS soclib_start_cpus() |
| 109 | INIT_SOCLIB_SMP_WAIT_BOOTSTRAP soclib_smp_wait_bootstrap() |
| 110 | INIT_DEVICE_CPU_REGS libdevice_cpu_regs_initsmp() |
| 111 | INIT_MUTEK_FAULT_HANDLER mutek_fault_initsmp() |
| 112 | INIT_MUTEK_SCHEDULER_INIT mutek_scheduler_initsmp() |
| 113 | INIT_MUTEK_CONSOLE mutek_console_initsmp() |
| 114 | INIT_APPLICATION mutek_app_initsmp() |
| 115 | INIT_MUTEK_SCHEDULER_START mutek_scheduler_start() |
| 116 | }}} |