wiki:boot_loader

Version 18 (modified by alain, 10 years ago) (diff)

--

GIET_VM / Boot Procedure

The boot procedure is done in three phases:

  • The generic reset code (hard-coded in the external ROM) is executed by processor (0,0,0), and load the GIET_VM boot-loader code, stored in the boot.elf file, from the external disk to the physical memory.
  • The GIET_VM boot-loader is executed in parallel by all processors (x,y,0). It load the map.bin file, build the page tables, initializes the schedulers as specified in the mapping, initializes the peripherals, and load the kernel code, as well as the user application(s) code into memory.
  • Finally, the GIET_VM kernel_init() function is executed by all processors, and completes the kernel initialization.

Phase 1 : Reset Initialization

In case of hard reset, all processors execute the same reset code (also called preloader code) stored in the external ROM, but the work done depends on the processor global index. This reset code is generic, and can be used to boot any operating system:

  • Processor P(0,0,0) load the GIET_VM boot-loader code from the external disk (or any other mass storage peripheral), to the physical memory bank of cluster(0,0).
  • All other processors initialize their private interrupt controller, to be able to receive an inter-processor interrupt (WTI), and enter wait_state in low-power mode.

Phase 2 : Boot Initialisation

The GIET_VM boot-loader is defined in the boot.c file. The main steps are the following:

step 1

Processor P(0,0,0) initializes the FAT, initializes the TTY0 lock, initialises the synchronisation barrier, and load the map.binfile. Then processor P(0,0,0) use inter-processor-interrupts (WTI) to start the parallel execution, and activate processor P(x,y,0) in all clusters containing processors.

step2

In each cluster(x,y), processor P(x,y,0) makes the physical memory allocators initialisation (function boot_pmem_init() ). The GIET VM uses two types of pages: BPP (Big Physical Page, 2 Mbytes), and SPP (Small Physical Page, 4 Kbytes). There is one SPP and one BPP allocator per cluster containing a physical memory bank. All the physical memory allocation must be done by the boot-loader in the boot phase, and these memory allocators should not be used by the kernel in the execution phase.

step 3

In each cluster(x,y), processor P(x,y,0) makes the local page table initialisation (function boot_ptabs_init()) as specified in the mapping. There is one page table per user application (vspace) defined in the mapping, and it is replicated in all clusters containing processors. In each cluster, all pages tables are packed in one segment (seg_ptab) occupying one single big page (2 Mbytes). Global vsegs are mapped in all vspaces. Any vseg (but the peripherals)can be mapped on any physical segment. As the kernel read-only segments (seg_kcode and seg_kinit) are replicated in all clusters to avoid contention, the content of the page tables depends on the cluster-coordinates: for the kernel code, a given virtual address is mapped to different physical addresses, depending on the cluster coordinates.

step 4

In each cluster(x,y), processor P(x,y,0) makes the schedulers initialization for all processors in the cluster (function boot_schedulers init()) as specified in the mapping:

  • There is one scheduler per processor.
  • Any task defined in any application can be allocated to any processor.
  • The allocation of task to processors is fully static (no task migration).
  • One single processor cannot schedule more than 14 tasks.
    • One scheduler occupies 8 Kbytes, and contains the contexts of all tasks allocated to the processor (256 bytes per task).

step 5

Finally, processor P(0,0,0) makes peripherals initialisation (function boot_peripherals_init()), coprocessors initialisation, and load into memory the kernel code (kernel.elf file), and the user code for all applications specified in the mapping (function boot_elf_load()).

step 6

Finally, in each cluster(x,y) processor(x,y,0) starts all other processors in the cluster, using an inter-processor interrupt (WTI). Each processor initializes its own CP0_SCHED register, its own CP2_MODE register to activates its MMU, its own CP0_SR register to use the GIET_VM exception handler, and jumps to the kernel_init() function.

Phase 3 : Kernel Initialisation

This code is executed by all processors, but sequencially. All processors enter the same kernel_init.c code that makes the following actions:

  • step 0 : processor[0][0][0] makes kernel_heap[x][y] array and kernel fat initialisation.
  • step 1 : each processor get its scheduler virtual address from CP0_SCHED register and contributes to _schedulers[x][y][p] array initialisation.
  • step 2 : each processor loops on all allocated tasks to build the _ptabs_vaddr[vspace] & _ptabs_ptprs[vspace] arrays from the tasks contexts.
  • step 3 : each processor computes and set the XCU masks, as specified in the HWI, PTI, and WTI interrupt vectors.
  • step 4 : each processor starts its TICK timer if it has at least one task allocated.
  • step 5 : each processor updates the idle_task context (CTX_SP, CTX_RA, CTX_EPC).
  • step 6 : when all processors reach the synchronisation barrier, each processor set registers SP, SR, PTPR, EPC, with the values corresponding to the first allocated task, and jump to user code.