source: soft/giet_vm/giet_boot/boot.c @ 467

Last change on this file since 467 was 464, checked in by alain, 10 years ago

Define the kernel_heap[X_SIZE][Y_SIZE] global variables,
and the TTY related global variables in boot.c.

File size: 83.7 KB
RevLine 
[412]1/////////////////////////////////////////////////////////////////////////////////////////
[258]2// File     : boot.c
3// Date     : 01/11/2013
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6//////////////////////////////////////////////////////////////////////////////////////////
7// The boot.c file is part of the GIET-VM nano-kernel.
8//
9// This nano-kernel has been written for the MIPS32 processor.
[359]10// The virtual adresses are on 32 bits and use the (unsigned int) type. The
[258]11// physicals addresses can have up to 40 bits, and use the  (unsigned long long) type.
[412]12// It natively supports clusterised shared memory multi-processors architectures,
[263]13// where each processor is identified by a composite index (cluster_xy, local_id),
[258]14// and where there is one physical memory bank per cluster.
15//
[359]16// This code, executed in the boot phase by proc[0,0,0], performs the following tasks:
17// - load into memory various binary files, from a FAT32 file system,
[258]18// - build the various page tables (one page table per vspace)
19// - initialize the shedulers (one scheduler per processor)
20//
21// 1) The binary files to be loaded are:
22//    - the "map.bin" file contains the hardware architecture description and the
23//      mapping directives. It must be stored in the the seg_boot_mapping segment
[321]24//      (at address SEG_BOOT_MAPPING_BASE defined in hard_config.h file).
[258]25//    - the "sys.elf" file contains the kernel binary code and data.
26//    - the various "application.elf" files.
27//
28// 2) The map.bin file contains the binary representation of the map.xml file defining:
29//    - the hardware architecture: number of clusters, number or processors,
30//      size of the memory segments, and peripherals in each cluster.
31//    - The structure of the various multi-threaded software applications:
32//      number of tasks, communication channels.
[309]33//    - The mapping: grouping of virtual objects (vobj) in the virtual segments (vseg),
[258]34//      placement of virtual segments (vseg) in the physical segments (pseg), placement
35//      of software tasks on the processors,
36//
37// 3) The GIET-VM uses the paged virtual memory to provides two services:
38//    - classical memory protection, when several independant applications compiled
39//      in different virtual spaces are executing on the same hardware platform.
[412]40//    - data placement in NUMA architectures, to control the placement
41//      of the software objects (vsegs) on the physical memory banks (psegs).
[258]42//
[412]43//    The max number of vspaces (GIET_NB_VSPACE_MAX) is a configuration parameter.
[258]44//    The page table are statically build in the boot phase, and they do not
[412]45//    change during execution.
46//    The GIET_VM uses both small pages (4 Kbytes), and big pages (2 Mbytes).
[258]47//
48//    Each page table (one page table per virtual space) is monolithic, and contains
[412]49//    one PT1 (8 Kbytes) and a variable number of PT2s (4 Kbytes each). For each vspace,
50//    the numberof PT2s is defined by the size of the PTAB vobj in the mapping.
51//    The PT1 is indexed by the ix1 field (11 bits) of the VPN. Each entry is 32 bits.
52//    A PT2 is indexed the ix2 field (9 bits) of the VPN. Each entry is a double word.
53//    The first word contains the flags, the second word contains the PPN.
54//
[464]55//    When this is required in the mapping, the page tables can be replicated
56//    in all clusters.
[263]57///////////////////////////////////////////////////////////////////////////////////////
58// Implementation Notes:
59//
60// 1) The cluster_id variable is a linear index in the mapping_info array of clusters.
61//    We use the cluster_xy variable for the tological index = x << Y_WIDTH + y
[412]62//
[263]63///////////////////////////////////////////////////////////////////////////////////////
[258]64
[263]65#include <giet_config.h>
[464]66#include <hard_config.h>
[436]67#include <mapping_info.h>
[464]68#include <kernel_malloc.h>
[258]69#include <barrier.h>
70#include <memspace.h>
71#include <tty_driver.h>
72#include <xcu_driver.h>
[347]73#include <bdv_driver.h>
[460]74#include <hba_driver.h>
[258]75#include <dma_driver.h>
76#include <cma_driver.h>
77#include <nic_driver.h>
78#include <ioc_driver.h>
[299]79#include <iob_driver.h>
[295]80#include <pic_driver.h>
[258]81#include <mwr_driver.h>
82#include <ctx_handler.h>
83#include <irq_handler.h>
84#include <vmem.h>
[412]85#include <pmem.h>
[258]86#include <utils.h>
[460]87#include <tty0.h>
[464]88#include <locks.h>
[258]89#include <elf-types.h>
90#include <fat32.h>
91#include <mips32_registers.h>
92#include <stdarg.h>
93
[263]94#if !defined(X_SIZE)
[359]95# error: The X_SIZE value must be defined in the 'hard_config.h' file !
[258]96#endif
97
[263]98#if !defined(Y_SIZE)
[359]99# error: The Y_SIZE value must be defined in the 'hard_config.h' file !
[263]100#endif
101
102#if !defined(X_WIDTH)
[359]103# error: The X_WIDTH value must be defined in the 'hard_config.h' file !
[263]104#endif
105
106#if !defined(Y_WIDTH)
[359]107# error: The Y_WIDTH value must be defined in the 'hard_config.h' file !
[263]108#endif
109
[321]110#if !defined(SEG_BOOT_MAPPING_BASE)
[359]111# error: The SEG_BOOT_MAPPING_BASE value must be defined in the hard_config.h file !
[321]112#endif
113
[359]114#if !defined(NB_PROCS_MAX)
115# error: The NB_PROCS_MAX value must be defined in the 'hard_config.h' file !
[321]116#endif
117
[359]118#if !defined(GIET_NB_VSPACE_MAX)
119# error: The GIET_NB_VSPACE_MAX value must be defined in the 'giet_config.h' file !
[321]120#endif
121
[359]122#if !defined(GIET_ELF_BUFFER_SIZE)
123# error: The GIET_ELF_BUFFER_SIZE value must be defined in the giet_config.h file !
[258]124#endif
125
126////////////////////////////////////////////////////////////////////////////
127//      Global variables for boot code
128////////////////////////////////////////////////////////////////////////////
129
[366]130extern void boot_entry();
131
[412]132// FAT internal representation for boot code 
133__attribute__((section (".bootdata"))) 
134fat32_fs_t             fat   __attribute__((aligned(512)));
[258]135
[412]136// Temporaty buffer used to load one complete .elf file 
[258]137__attribute__((section (".bootdata"))) 
[412]138char                   boot_elf_buffer[GIET_ELF_BUFFER_SIZE] __attribute__((aligned(512)));
[258]139
[412]140// Physical memory allocators array (one per cluster)
[258]141__attribute__((section (".bootdata"))) 
[412]142pmem_alloc_t           boot_pmem_alloc[X_SIZE][Y_SIZE];
[258]143
[464]144// Distributed kernel heap (one per cluster)
145__attribute__((section (".bootdata"))) 
146kernel_heap_t          kernel_heap[X_SIZE][Y_SIZE];
147
[412]148// Schedulers virtual base addresses array (one per processor)
[258]149__attribute__((section (".bootdata"))) 
[412]150static_scheduler_t*    _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX];
[258]151
[412]152// Page tables virtual base addresses array (one per vspace)
[258]153__attribute__((section (".bootdata"))) 
[412]154unsigned int           _ptabs_vaddr[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE];
[258]155
[412]156// Page tables physical base addresses (one per vspace and per cluster)
[263]157__attribute__((section (".bootdata"))) 
[412]158paddr_t                _ptabs_paddr[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE];
[258]159
[412]160// Page tables pt2 allocators (one per vspace and per cluster)
[359]161__attribute__((section (".bootdata"))) 
[412]162unsigned int           _ptabs_next_pt2[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE];
[263]163
[412]164// Page tables max_pt2  (same value for all page tables)
165__attribute__((section (".bootdata"))) 
166unsigned int           _ptabs_max_pt2;
167
[464]168// Global variables for TTY
169__attribute__((section (".bootdata"))) 
170sbt_lock_t             _tty_tx_lock[NB_TTY_CHANNELS]   __attribute__((aligned(64)));
171
172__attribute__((section (".bootdata"))) 
173unsigned int           _tty_rx_full[NB_TTY_CHANNELS];
174
175__attribute__((section (".bootdata"))) 
176unsigned int           _tty_rx_buf[NB_TTY_CHANNELS];
177
178
179
[258]180/////////////////////////////////////////////////////////////////////
181// This function checks consistence beween the  mapping_info data
182// structure (soft), and the giet_config file (hard).
183/////////////////////////////////////////////////////////////////////
184void boot_mapping_check() 
185{
[321]186    mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
[258]187
188    // checking mapping availability
189    if (header->signature != IN_MAPPING_SIGNATURE) 
190    {
191        _puts("\n[BOOT ERROR] Illegal mapping signature: ");
192        _putx(header->signature);
193        _puts("\n");
194        _exit();
195    }
[263]196
[258]197    // checking number of clusters
[263]198    if ( (header->x_size  != X_SIZE)  || 
199         (header->y_size  != Y_SIZE)  ||
200         (header->x_width != X_WIDTH) ||
201         (header->y_width != Y_WIDTH) )
[258]202    {
[263]203        _puts("\n[BOOT ERROR] Incoherent X_SIZE or Y_SIZE ");
204        _puts("\n             - In hard_config:  X_SIZE = ");
205        _putd( X_SIZE );
206        _puts(" / Y_SIZE = ");
207        _putd( Y_SIZE );
208        _puts(" / X_WIDTH = ");
209        _putd( X_WIDTH );
210        _puts(" / Y_WIDTH = ");
211        _putd( Y_WIDTH );
212        _puts("\n             - In mapping_info: x_size = ");
213        _putd( header->x_size );
214        _puts(" / y_size = ");
215        _putd( header->y_size );
216        _puts(" / x_width = ");
217        _putd( header->x_width );
218        _puts(" / y_width = ");
219        _putd( header->y_width );
[258]220        _puts("\n");
221        _exit();
222    }
223    // checking number of virtual spaces
224    if (header->vspaces > GIET_NB_VSPACE_MAX) 
225    {
226        _puts("\n[BOOT ERROR] : number of vspaces > GIET_NB_VSPACE_MAX\n");
227        _puts("\n");
228        _exit();
229    }
230
231#if BOOT_DEBUG_MAPPING
[263]232_puts("\n - x_size    = ");
233_putd( header->x_size );
234_puts("\n - y_size    = ");
235_putd( header->y_size );
[258]236_puts("\n - procs     = ");
237_putd( header->procs );
238_puts("\n - periphs   = ");
239_putd( header->periphs );
240_puts("\n - vspaces   = ");
241_putd( header->vspaces );
242_puts("\n - tasks     = ");
243_putd( header->tasks );
244_puts("\n");
245_puts("\n - size of header  = ");
246_putd( MAPPING_HEADER_SIZE );
247_puts("\n - size of cluster = ");
248_putd( MAPPING_CLUSTER_SIZE );
249_puts("\n - size of pseg    = ");
250_putd( MAPPING_PSEG_SIZE );
251_puts("\n - size of proc    = ");
252_putd( MAPPING_PROC_SIZE );
253_puts("\n - size of vspace  = ");
254_putd( MAPPING_VSPACE_SIZE );
255_puts("\n - size of vseg    = ");
256_putd( MAPPING_VSEG_SIZE );
257_puts("\n - size of vobj    = ");
258_putd( MAPPING_VOBJ_SIZE );
259_puts("\n - size of task    = ");
260_putd( MAPPING_TASK_SIZE );
261_puts("\n");
262
[263]263unsigned int cluster_id;
[258]264mapping_cluster_t * cluster = _get_cluster_base(header);
[263]265for( cluster_id = 0; cluster_id < X_SIZE*Y_SIZE ; cluster_id++) 
[258]266{
[263]267    _puts("\n - cluster[");
268    _putd( cluster[cluster_id].x );
269    _puts(",");
270    _putd( cluster[cluster_id].y );
271    _puts("]\n   procs   = ");
272    _putd( cluster[cluster_id].procs );
273    _puts("\n   psegs   = ");
274    _putd( cluster[cluster_id].psegs );
275    _puts("\n   periphs = ");
276    _putd( cluster[cluster_id].periphs );
277    _puts("\n");
[258]278}
279#endif
280
281} // end boot_mapping_check()
282
283//////////////////////////////////////////////////////////////////////////////
[412]284// This function registers a new PTE1 in the page table defined
285// by the vspace_id argument, and the (x,y) coordinates.
286// It updates only the first level PT1.
[258]287//////////////////////////////////////////////////////////////////////////////
[412]288void boot_add_pte1( unsigned int vspace_id,
289                    unsigned int x,
290                    unsigned int y,
291                    unsigned int vpn,        // 20 bits right-justified
292                    unsigned int flags,      // 10 bits left-justified
293                    unsigned int ppn )       // 28 bits right-justified
[258]294{
[427]295
296#if (BOOT_DEBUG_PT > 1)
297_puts(" - PTE1 in PTAB[");
298_putd( vspace_id );
299_puts(",");
300_putd( x );
301_puts(",");
302_putd( y );
303_puts("] : vpn = ");
304_putx( vpn );
305#endif
306
[412]307    // compute index in PT1
308    unsigned int    ix1 = vpn >> 9;         // 11 bits for ix1
[258]309
[412]310    // get page table physical base address
311    paddr_t         pt1_pbase = _ptabs_paddr[vspace_id][x][y];
312
313    // check pt1_base
314    if ( pt1_pbase == 0 )
[258]315    {
[412]316        _puts("\n[BOOT ERROR] in boot_add_pte1() : illegal pbase address for PTAB[");
317        _putd( vspace_id );
318        _puts(",");
319        _putd( x );
320        _puts(",");
321        _putd( y );
322        _puts("]\n");
[258]323        _exit();
324    }
325
[412]326    // compute pte1 : 2 bits V T / 8 bits flags / 3 bits RSVD / 19 bits bppi
327    unsigned int    pte1 = PTE_V |
328                           (flags & 0x3FC00000) |
329                           ((ppn>>9) & 0x0007FFFF);
[258]330
[412]331    // write pte1 in PT1
332    _physical_write( pt1_pbase + 4*ix1, pte1 );
333
334#if (BOOT_DEBUG_PT > 1)
335_puts(" / ppn = ");
336_putx( ppn );
337_puts(" / flags = ");
338_putx( flags );
339_puts("\n");
340#endif
341
342}   // end boot_add_pte1()
343
[258]344//////////////////////////////////////////////////////////////////////////////
[412]345// This function registers a new PTE2 in the page table defined
[347]346// by the vspace_id argument, and the (x,y) coordinates.
[412]347// It updates both the first level PT1 and the second level PT2.
[258]348// As the set of PT2s is implemented as a fixed size array (no dynamic
349// allocation), this function checks a possible overflow of the PT2 array.
350//////////////////////////////////////////////////////////////////////////////
[412]351void boot_add_pte2( unsigned int vspace_id,
352                    unsigned int x,
353                    unsigned int y,
354                    unsigned int vpn,        // 20 bits right-justified
355                    unsigned int flags,      // 10 bits left-justified
356                    unsigned int ppn )       // 28 bits right-justified
[258]357{
[427]358
359#if (BOOT_DEBUG_PT > 1)
360_puts(" - PTE2 in PTAB[");
361_putd( vspace_id );
362_puts(",");
363_putd( x );
364_puts(",");
365_putd( y );
366_puts("] : vpn = ");
367_putx( vpn );
368#endif
369
[258]370    unsigned int ix1;
371    unsigned int ix2;
[347]372    paddr_t      pt2_pbase;     // PT2 physical base address
[412]373    paddr_t      pte2_paddr;    // PTE2 physical address
[258]374    unsigned int pt2_id;        // PT2 index
375    unsigned int ptd;           // PTD : entry in PT1
376
[412]377    ix1 = vpn >> 9;             // 11 bits for ix1
378    ix2 = vpn & 0x1FF;          //  9 bits for ix2
[258]379
[347]380    // get page table physical base address and size
381    paddr_t      pt1_pbase = _ptabs_paddr[vspace_id][x][y];
[258]382
[412]383    // check pt1_base
384    if ( pt1_pbase == 0 )
[258]385    {
[412]386        _puts("\n[BOOT ERROR] in boot_add_pte2() : PTAB[");
387        _putd( vspace_id );
388        _puts(",");
389        _putd( x );
390        _puts(",");
391        _putd( y );
392        _puts("] undefined\n");
[258]393        _exit();
394    }
395
396    // get ptd in PT1
397    ptd = _physical_read(pt1_pbase + 4 * ix1);
398
[347]399    if ((ptd & PTE_V) == 0)    // undefined PTD: compute PT2 base address,
[258]400                               // and set a new PTD in PT1
401    {
[347]402        pt2_id = _ptabs_next_pt2[vspace_id][x][y];
[412]403        if (pt2_id == _ptabs_max_pt2) 
[258]404        {
[412]405            _puts("\n[BOOT ERROR] in boot_add_pte2() : PTAB[");
406            _putd( vspace_id );
407            _puts(",");
408            _putd( x );
409            _puts(",");
410            _putd( y );
411            _puts("] contains not enough PT2s\n");
[258]412            _exit();
413        }
[347]414
415        pt2_pbase = pt1_pbase + PT1_SIZE + PT2_SIZE * pt2_id;
416        ptd = PTE_V | PTE_T | (unsigned int) (pt2_pbase >> 12);
[412]417        _physical_write( pt1_pbase + 4*ix1, ptd);
[347]418        _ptabs_next_pt2[vspace_id][x][y] = pt2_id + 1;
[258]419    }
420    else                       // valid PTD: compute PT2 base address
421    {
422        pt2_pbase = ((paddr_t)(ptd & 0x0FFFFFFF)) << 12;
423    }
424
425    // set PTE in PT2 : flags & PPN in two 32 bits words
[412]426    pte2_paddr  = pt2_pbase + 8 * ix2;
427    _physical_write(pte2_paddr     , (PTE_V |flags) );
428    _physical_write(pte2_paddr + 4 , ppn);
[258]429
[412]430#if (BOOT_DEBUG_PT > 1)
431_puts(" / ppn = ");
432_putx( ppn );
433_puts(" / flags = ");
434_putx( flags );
[347]435_puts("\n");
[258]436#endif
437
[412]438}   // end boot_add_pte2()
[258]439
[412]440////////////////////////////////////////////////////////////////////////////////////
[258]441// Align the value of paddr or vaddr to the required alignement,
442// defined by alignPow2 == L2(alignement).
[412]443////////////////////////////////////////////////////////////////////////////////////
[258]444paddr_t paddr_align_to(paddr_t paddr, unsigned int alignPow2) 
445{
446    paddr_t mask = (1 << alignPow2) - 1;
447    return ((paddr + mask) & ~mask);
448}
449
450unsigned int vaddr_align_to(unsigned int vaddr, unsigned int alignPow2) 
451{
452    unsigned int mask = (1 << alignPow2) - 1;
453    return ((vaddr + mask) & ~mask);
454}
455
[412]456/////////////////////////////////////////////////////////////////////////////////////
457// This function map a vseg identified by the vseg pointer.
458//
459// A given vseg can be mapped in Big Physical Pages (BPP: 2 Mbytes) or in a
460// Small Physical Pages (SPP: 4 Kbytes), depending on the "big" attribute of vseg,
461// with the following rules:
462// - SPP : There is only one vseg in a small physical page, but a single vseg
463//   can cover several contiguous small physical pages.
464// - BPP : It can exist several vsegs in a single big physical page, and a single
465//   vseg can cover several contiguous big physical pages.
466//
467// 1) First step: it computes the vseg length, and register it in vseg->length field.
468//    It computes - for each vobj - the actual vbase address, taking into
469//    account the alignment constraints and register it in vobj->vbase field.
470//
471// 2) Second step: it allocates the required number of physical pages,
472//    computes the physical base address (if the vseg is not identity mapping),
473//    and register it in the vseg pbase field.
474//    Only the 4 vsegs used by the boot code and the peripheral vsegs
475//    can be identity mapping: The first big physical page in cluster[0,0]
476//    is reserved for the 4 boot vsegs.
477//
478// 3) Third step (only for vseg that have the VOBJ_TYPE_PTAB): all page tables
479//    associated to the various vspaces must be packed in the same vseg.
480//    We divide the vseg in M sub-segments, and compute the vbase and pbase
481//    addresses for each page table, and register it in the _ptabs_paddr
482//    and _ptabs_vaddr arrays.
483// 
484/////////////////////////////////////////////////////////////////////////////////////
[427]485void boot_vseg_map( mapping_vseg_t* vseg,
486                    unsigned int    vspace_id )
[258]487{
[412]488    mapping_header_t*   header  = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
489    mapping_vobj_t*     vobj    = _get_vobj_base(header);
490    mapping_cluster_t*  cluster = _get_cluster_base(header);
491    mapping_pseg_t*     pseg    = _get_pseg_base(header);
[258]492
[412]493    // compute destination cluster pointer & coordinates
494    pseg    = pseg + vseg->psegid;
495    cluster = cluster + pseg->clusterid;
496    unsigned int        x_dest     = cluster->x;
497    unsigned int        y_dest     = cluster->y;
[258]498
[412]499    // compute the first vobj global index
500    unsigned int        vobj_id = vseg->vobj_offset;
501   
502    // compute the "big" vseg attribute
503    unsigned int        big = vseg->big;
[258]504
[412]505    // compute the "is_ram" vseg attribute
506    unsigned int        is_ram;
507    if ( pseg->type == PSEG_TYPE_RAM )  is_ram = 1;
508    else                                is_ram = 0;
[258]509
[412]510    // compute the "is_ptab" attribute
511    unsigned int        is_ptab;
512    if ( vobj[vobj_id].type == VOBJ_TYPE_PTAB ) is_ptab = 1;
513    else                                        is_ptab = 0;
[258]514
[427]515    // compute actual vspace index
516    unsigned int vsid;
517    if ( vspace_id == 0xFFFFFFFF ) vsid = 0;
518    else                           vsid = vspace_id;
519
[412]520    //////////// First step : compute vseg length and vobj(s) vbase
[258]521
[412]522    unsigned int vobj_vbase = vseg->vbase;   // min vbase for first vobj
[258]523
[412]524    for ( vobj_id = vseg->vobj_offset ;
525          vobj_id < (vseg->vobj_offset + vseg->vobjs) ; 
526          vobj_id++ ) 
[258]527    {
[412]528        // compute and register vobj vbase
529        vobj[vobj_id].vbase = vaddr_align_to( vobj_vbase, vobj[vobj_id].align );
530   
531        // compute min vbase for next vobj
532        vobj_vbase = vobj[vobj_id].vbase + vobj[vobj_id].length;
[258]533    }
534
[412]535    // compute and register vseg length (multiple of 4 Kbytes)
536    vseg->length = vaddr_align_to( vobj_vbase - vseg->vbase, 12 );
537   
538    //////////// Second step : compute ppn and npages 
539    //////////// - if identity mapping :  ppn <= vpn
540    //////////// - if vseg is periph   :  ppn <= pseg.base >> 12
541    //////////// - if vseg is ram      :  ppn <= physical memory allocator
[258]542
[412]543    unsigned int ppn;          // first physical page index ( 28 bits = |x|y|bppi|sppi| )
544    unsigned int vpn;          // first virtual page index  ( 20 bits = |ix1|ix2| )
545    unsigned int vpn_max;      // last  virtual page index  ( 20 bits = |ix1|ix2| )
[258]546
[412]547    vpn     = vseg->vbase >> 12;
548    vpn_max = (vseg->vbase + vseg->length - 1) >> 12;
[258]549
[412]550    // compute npages
551    unsigned int npages;       // number of required (big or small) pages
552    if ( big == 0 ) npages  = vpn_max - vpn + 1;            // number of small pages
553    else            npages  = (vpn_max>>9) - (vpn>>9) + 1;  // number of big pages
554
555    // compute ppn
556    if ( vseg->ident )           // identity mapping
[258]557    {
[412]558        ppn = vpn;
[258]559    }
[412]560    else                         // not identity mapping
[258]561    {
[412]562        if ( is_ram )            // RAM : physical memory allocation required
[258]563        {
[412]564            // compute pointer on physical memory allocator in dest cluster
565            pmem_alloc_t*     palloc = &boot_pmem_alloc[x_dest][y_dest];
[258]566
[412]567            if ( big == 0 )             // SPP : small physical pages
568            {
569                // allocate contiguous small physical pages
570                ppn = _get_small_ppn( palloc, npages );
571            }
572            else                            // BPP : big physical pages
573            {
574 
575                // one big page can be shared by several vsegs
576                // we must chek if BPP already allocated
577                if ( is_ptab )   // It cannot be mapped
578                {
579                    ppn = _get_big_ppn( palloc, npages ); 
580                }
581                else             // It can be mapped
582                {
583                    unsigned int ix1   = vpn >> 9;   // 11 bits
[427]584                    paddr_t      paddr = _ptabs_paddr[vsid][x_dest][y_dest] + (ix1<<2);
[412]585                    unsigned int pte1  = _physical_read( paddr );
586                    if ( (pte1 & PTE_V) == 0 )     // BPP not allocated yet
587                    {
588                        // allocate contiguous big physical pages
[433]589                        ppn = _get_big_ppn( palloc, npages );
[412]590                    }
591                    else                           // BPP already allocated
592                    {
[433]593                        // test if new vseg has the same mode bits than
594                        // the other vsegs in the same big page
595                        unsigned int pte1_mode = 0;
596                        if (pte1 & PTE_C) pte1_mode |= C_MODE_MASK;
597                        if (pte1 & PTE_X) pte1_mode |= X_MODE_MASK;
598                        if (pte1 & PTE_W) pte1_mode |= W_MODE_MASK;
599                        if (pte1 & PTE_U) pte1_mode |= U_MODE_MASK;
600                        if (vseg->mode != pte1_mode) {
601                            _puts("\n[BOOT ERROR] in boot_vseg_map() : vseg ");
602                            _puts( vseg->name );
603                            _puts(" has different flags (");
604                            _putx( vseg->mode );
605                            _puts(") than other vsegs sharing the same big page (");
606                            _putx( pte1_mode );
607                            _puts(")");
608                            _exit();
609                        }
610
[412]611                        ppn = ((pte1 << 9) & 0x0FFFFE00);
612                    }
613                }
614                ppn = ppn | (vpn & 0x1FF);
615            }
[258]616        }
[412]617        else                    // PERI : no memory allocation required
[258]618        {
[412]619            ppn = pseg->base >> 12;
[258]620        }
621    }
622
[412]623    // update vseg.pbase field and update vsegs chaining
624    vseg->pbase     = ((paddr_t)ppn) << 12;
625    vseg->next_vseg = pseg->next_vseg;
626    pseg->next_vseg = (unsigned int)vseg;
[258]627
[412]628
629    //////////// Third step : (only if the vseg is a page table)
630    //////////// - compute the physical & virtual base address for each vspace
631    ////////////   by dividing the vseg in several sub-segments.
632    //////////// - register it in _ptabs_vaddr & _ptabs_paddr arrays,
[427]633    ////////////   and initialize next_pt2 allocators.
634    //////////// - reset all entries in first level page tables
[412]635   
636    if ( is_ptab )
[258]637    {
[412]638        unsigned int   vs;        // vspace index
639        unsigned int   nspaces;   // number of vspaces
640        unsigned int   nsp;       // number of small pages for one PTAB
641        unsigned int   offset;    // address offset for current PTAB
[258]642
[412]643        nspaces = header->vspaces;
644        offset  = 0;
[258]645
[412]646        // each PTAB must be aligned on a 8 Kbytes boundary
[427]647        nsp = ( vseg->length >> 12 ) / nspaces;
[412]648        if ( (nsp & 0x1) == 0x1 ) nsp = nsp - 1;
[258]649
[412]650        // compute max_pt2
651        _ptabs_max_pt2 = ((nsp<<12) - PT1_SIZE) / PT2_SIZE;
[433]652
[412]653        for ( vs = 0 ; vs < nspaces ; vs++ )
[258]654        {
[433]655            _ptabs_vaddr   [vs][x_dest][y_dest] = (vpn + offset) << 12;
[412]656            _ptabs_paddr   [vs][x_dest][y_dest] = ((paddr_t)(ppn + offset)) << 12;
657            _ptabs_next_pt2[vs][x_dest][y_dest] = 0;
[427]658            offset += nsp;
[433]659
[427]660            // reset all entries in PT1 (8 Kbytes)
661            _physical_memset( _ptabs_paddr[vs][x_dest][y_dest], PT1_SIZE, 0 );
[258]662        }
663    }
664
[412]665#if BOOT_DEBUG_PT
666_puts("[BOOT DEBUG] ");
[433]667_puts( vseg->name );
[412]668_puts(" in cluster[");
669_putd( x_dest );
670_puts(",");
671_putd( y_dest );
672_puts("] : vbase = ");
673_putx( vseg->vbase );
674_puts(" / length = ");
675_putx( vseg->length );
676if ( big ) _puts(" / BIG   / npages = ");
677else       _puts(" / SMALL / npages = ");
678_putd( npages );
679_puts(" / pbase = ");
680_putl( vseg->pbase );
681_puts("\n");
682#endif
683
684} // end boot_vseg_map()
685
686/////////////////////////////////////////////////////////////////////////////////////
687// For the vseg defined by the vseg pointer, this function register all PTEs
688// in one or several page tables.
[436]689// It is a global vseg (kernel vseg) if (vspace_id == 0xFFFFFFFF).
[412]690// The number of involved PTABs depends on the "local" and "global" attributes:
691//  - PTEs are replicated in all vspaces for a global vseg.
692//  - PTEs are replicated in all clusters for a non local vseg.
693/////////////////////////////////////////////////////////////////////////////////////
[427]694void boot_vseg_pte( mapping_vseg_t*  vseg,
695                    unsigned int     vspace_id )
[412]696{
697    // compute the "global" vseg attribute and actual vspace index
698    unsigned int        global;
699    unsigned int        vsid;   
700    if ( vspace_id == 0xFFFFFFFF )
[258]701    {
[412]702        global = 1;
703        vsid   = 0;
[258]704    }
[412]705    else
[258]706    {
[412]707        global = 0;
708        vsid   = vspace_id;
[258]709    }
710
[412]711    // compute the "local" and "big" attributes
712    unsigned int        local  = vseg->local;
713    unsigned int        big    = vseg->big;
[258]714
[412]715    // compute vseg flags
716    // The three flags (Local, Remote and Dirty) are set to 1 to reduce
717    // latency of TLB miss (L/R) and write (D): Avoid hardware update
718    // mechanism for these flags because GIET_VM does use these flags.
719    unsigned int flags = 0;
720    if (vseg->mode & C_MODE_MASK) flags |= PTE_C;
721    if (vseg->mode & X_MODE_MASK) flags |= PTE_X;
722    if (vseg->mode & W_MODE_MASK) flags |= PTE_W;
723    if (vseg->mode & U_MODE_MASK) flags |= PTE_U;
724    if ( global )                 flags |= PTE_G;
725                                  flags |= PTE_L;
726                                  flags |= PTE_R;
727                                  flags |= PTE_D;
[258]728
[412]729    // compute VPN, PPN and number of pages (big or small)
730    unsigned int vpn     = vseg->vbase >> 12;
731    unsigned int vpn_max = (vseg->vbase + vseg->length - 1) >> 12;
732    unsigned int ppn     = (unsigned int)(vseg->pbase >> 12);
733    unsigned int npages;
734    if ( big == 0 ) npages  = vpn_max - vpn + 1;           
735    else            npages  = (vpn_max>>9) - (vpn>>9) + 1; 
736
737    // compute destination cluster coordinates
738    unsigned int        x_dest;
739    unsigned int        y_dest;
740    mapping_header_t*   header  = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
741    mapping_cluster_t*  cluster = _get_cluster_base(header);
742    mapping_pseg_t*     pseg    = _get_pseg_base(header);
743    pseg     = pseg + vseg->psegid;
744    cluster  = cluster + pseg->clusterid;
745    x_dest   = cluster->x;
746    y_dest   = cluster->y;
747
748    unsigned int p;     // iterator for physical page index
749    unsigned int x;     // iterator for cluster x coordinate 
750    unsigned int y;     // iterator for cluster y coordinate 
751    unsigned int v;     // iterator for vspace index
752
753    // loop on PTEs
754    for ( p = 0 ; p < npages ; p++ )
755    { 
756        if  ( (local != 0) && (global == 0) )         // one cluster  / one vspace
[258]757        {
[412]758            if ( big )   // big pages => PTE1s
759            {
760                boot_add_pte1( vsid,
761                               x_dest,
762                               y_dest,
763                               vpn + (p<<9),
764                               flags, 
765                               ppn + (p<<9) );
766            }
767            else         // small pages => PTE2s
768            {
769                boot_add_pte2( vsid,
770                               x_dest,
771                               y_dest,
772                               vpn + p,     
773                               flags, 
774                               ppn + p );
775            }
[258]776        }
[412]777        else if ( (local == 0) && (global == 0) )     // all clusters / one vspace
[258]778        {
[412]779            for ( x = 0 ; x < X_SIZE ; x++ )
[258]780            {
[412]781                for ( y = 0 ; y < Y_SIZE ; y++ )
782                {
783                    if ( big )   // big pages => PTE1s
784                    {
785                        boot_add_pte1( vsid,
786                                       x,
787                                       y,
788                                       vpn + (p<<9),
789                                       flags, 
790                                       ppn + (p<<9) );
791                    }
792                    else         // small pages => PTE2s
793                    {
794                        boot_add_pte2( vsid,
795                                       x,
796                                       y,
797                                       vpn + p,
798                                       flags, 
799                                       ppn + p );
800                    }
801                }
[258]802            }
[412]803        }
804        else if ( (local != 0) && (global != 0) )     // one cluster  / all vspaces
805        {
806            for ( v = 0 ; v < header->vspaces ; v++ )
[258]807            {
[412]808                if ( big )   // big pages => PTE1s
809                {
810                    boot_add_pte1( v,
811                                   x_dest,
812                                   y_dest,
813                                   vpn + (p<<9),
814                                   flags, 
815                                   ppn + (p<<9) );
816                }
817                else         // small pages = PTE2s
818                { 
819                    boot_add_pte2( v,
820                                   x_dest,
821                                   y_dest,
822                                   vpn + p,
823                                   flags, 
824                                   ppn + p );
825                }
[258]826            }
[412]827        }
828        else if ( (local == 0) && (global != 0) )     // all clusters / all vspaces
829        {
830            for ( x = 0 ; x < X_SIZE ; x++ )
[258]831            {
[412]832                for ( y = 0 ; y < Y_SIZE ; y++ )
833                {
834                    for ( v = 0 ; v < header->vspaces ; v++ )
835                    {
836                        if ( big )  // big pages => PTE1s
837                        {
838                            boot_add_pte1( v,
839                                           x,
840                                           y,
841                                           vpn + (p<<9),
842                                           flags, 
843                                           ppn + (p<<9) );
844                        }
845                        else        // small pages -> PTE2s
846                        {
847                            boot_add_pte2( v,
848                                           x,
849                                           y,
850                                           vpn + p,
851                                           flags, 
852                                           ppn + p );
853                        }
854                    }
855                }
[258]856            }
857        }
[412]858    }  // end for pages
[427]859}  // end boot_vseg_pte()
[258]860
[412]861///////////////////////////////////////////////////////////////////////////////
862// This function initialises the page tables for all vspaces defined
863// in the mapping_info data structure.
864// For each vspace, there is one page table per cluster.
865// In each cluster all page tables for the different vspaces must be
866// packed in one vseg occupying one single BPP (Big Physical Page).
[258]867//
[412]868// For each vseg, the mapping is done in two steps:
[436]869// 1) mapping : the boot_vseg_map() function allocates contiguous BPPs
[412]870//    or SPPs (if the vseg is not associated to a peripheral), and register
871//    the physical base address in the vseg pbase field. It initialises the
872//    _ptabs_vaddr and _ptabs_paddr arrays if the vseg is a PTAB.
873//
[436]874// 2) page table initialisation : the boot_vseg_pte() function initialise
[412]875//    the PTEs (both PTE1 and PTE2) in one or several page tables:
876//    - PTEs are replicated in all vspaces for a global vseg.
877//    - PTEs are replicated in all clusters for a non local vseg.
878//
879// We must handle vsegs in the following order
880//   1) all global vsegs containing a page table,
881//   2) all global vsegs occupying more than one BPP,
882//   3) all others global vsegs
883//   4) all private vsegs in user space.
884///////////////////////////////////////////////////////////////////////////////
[436]885void boot_ptabs_init() 
[258]886{
[412]887    mapping_header_t*   header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
888    mapping_vspace_t*   vspace = _get_vspace_base(header);
889    mapping_vseg_t*     vseg   = _get_vseg_base(header);
890    mapping_vobj_t*     vobj   = _get_vobj_base(header);
[258]891
892    unsigned int vspace_id;
893    unsigned int vseg_id;
894
895    if (header->vspaces == 0 )
896    {
[436]897        _puts("\n[BOOT ERROR] in boot_ptabs_init() : mapping ");
[258]898        _puts( header->name );
899        _puts(" contains no vspace\n");
900        _exit();
901    }
902
[412]903    ///////// Phase 1 : global vsegs containing a PTAB (two loops required)
904
[258]905#if BOOT_DEBUG_PT
[412]906_puts("\n[BOOT DEBUG] map PTAB global vsegs\n");
[258]907#endif
908
[412]909    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 
910    {
911        unsigned int vobj_id = vseg[vseg_id].vobj_offset;
912        if ( (vobj[vobj_id].type == VOBJ_TYPE_PTAB) )
913        {
[427]914            boot_vseg_map( &vseg[vseg_id], 0xFFFFFFFF );
[412]915            vseg[vseg_id].mapped = 1;
916        }
917    }
[258]918
919    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 
920    {
[412]921        unsigned int vobj_id = vseg[vseg_id].vobj_offset;
922        if ( (vobj[vobj_id].type == VOBJ_TYPE_PTAB) )
923        {
[427]924            boot_vseg_pte( &vseg[vseg_id], 0xFFFFFFFF );
[412]925            vseg[vseg_id].mapped = 1;
926        }
[258]927    }
928
[412]929    ///////// Phase 2 : global vsegs occupying more than one BPP (one loop)
930
931#if BOOT_DEBUG_PT
932_puts("\n[BOOT DEBUG] map all multi-BPP global vsegs\n");
933#endif
934
[258]935    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 
936    {
[412]937        unsigned int vobj_id = vseg[vseg_id].vobj_offset;
938        if ( (vobj[vobj_id].length > 0x200000) &&
939             (vseg[vseg_id].mapped == 0) )
940        {
[427]941            boot_vseg_map( &vseg[vseg_id], 0xFFFFFFFF );
[412]942            vseg[vseg_id].mapped = 1;
[427]943            boot_vseg_pte( &vseg[vseg_id], 0xFFFFFFFF );
[412]944        }
[258]945    }
946
[412]947    ///////// Phase 3 : all others global vsegs (one loop)
[347]948
[412]949#if BOOT_DEBUG_PT
950_puts("\n[BOOT DEBUG] map all others global vsegs\n");
951#endif
952
953    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 
954    {
955        if ( vseg[vseg_id].mapped == 0 )
956        {
[427]957            boot_vseg_map( &vseg[vseg_id], 0xFFFFFFFF );
[412]958            vseg[vseg_id].mapped = 1;
[427]959            boot_vseg_pte( &vseg[vseg_id], 0xFFFFFFFF );
[412]960        }
961    }
962
963    ///////// Phase 4 : all private vsegs (two nested loops)
964
[258]965    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
966    {
967
968#if BOOT_DEBUG_PT
[412]969_puts("\n[BOOT DEBUG] map private vsegs for vspace ");
970_puts( vspace[vspace_id].name );
971_puts("\n");
[258]972#endif
973
974        for (vseg_id = vspace[vspace_id].vseg_offset;
975             vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
976             vseg_id++) 
977        {
[427]978            boot_vseg_map( &vseg[vseg_id], vspace_id );
[412]979            vseg[vseg_id].mapped = 1;
[427]980            boot_vseg_pte( &vseg[vseg_id], vspace_id );
[258]981        }
982    }
983
[412]984#if (BOOT_DEBUG_PT > 1)
[309]985mapping_vseg_t*    curr;
986mapping_pseg_t*    pseg    = _get_pseg_base(header);
987mapping_cluster_t* cluster = _get_cluster_base(header);
988unsigned int       pseg_id;
[258]989for( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ )
990{
[309]991    unsigned int cluster_id = pseg[pseg_id].clusterid;
[412]992    _puts("\n[BOOT DEBUG] vsegs mapped on pseg ");
[258]993    _puts( pseg[pseg_id].name );
[309]994    _puts(" in cluster[");
995    _putd( cluster[cluster_id].x );
996    _puts(",");
997    _putd( cluster[cluster_id].y );
[412]998    _puts("]\n");
[258]999    for( curr = (mapping_vseg_t*)pseg[pseg_id].next_vseg ;
1000         curr != 0 ;
1001         curr = (mapping_vseg_t*)curr->next_vseg )
1002    {
1003        _puts(" - vseg ");
1004        _puts( curr->name );
1005        _puts(" : len = ");
1006        _putx( curr->length );
1007        _puts(" / vbase ");
[295]1008        _putx( curr->vbase );
[258]1009        _puts(" / pbase ");
1010        _putl( curr->pbase );
1011        _puts("\n");
1012    } 
1013}
1014#endif
1015
[412]1016} // end boot_ptabs_init()
[258]1017
1018///////////////////////////////////////////////////////////////////////////////
[452]1019// This function initializes the private vobjs that have the CONST type.
[258]1020// The MMU is supposed to be activated...
1021///////////////////////////////////////////////////////////////////////////////
1022void boot_vobjs_init() 
1023{
[321]1024    mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
[258]1025    mapping_vspace_t* vspace = _get_vspace_base(header);
1026    mapping_vobj_t* vobj     = _get_vobj_base(header);
1027
1028    unsigned int vspace_id;
1029    unsigned int vobj_id;
1030
1031    // loop on the vspaces
1032    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
1033    {
1034
1035#if BOOT_DEBUG_VOBJS
1036_puts("\n[BOOT DEBUG] ****** vobjs initialisation in vspace ");
1037_puts(vspace[vspace_id].name);
1038_puts(" ******\n");
1039#endif
1040
[347]1041        _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[vspace_id][0][0] >> 13) );
[258]1042
1043        // loop on the vobjs
1044        for (vobj_id = vspace[vspace_id].vobj_offset;
1045             vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs);
1046             vobj_id++) 
1047        {
[452]1048            if ( (vobj[vobj_id].type) == VOBJ_TYPE_CONST )
[258]1049            {
[309]1050#if BOOT_DEBUG_VOBJS
[258]1051_puts("CONST   : ");
1052_puts(vobj[vobj_id].name);
[452]1053_puts(" / vaddr  = ");
[309]1054_putx(vobj[vobj_id].vaddr);
[452]1055_puts(" / paddr  = ");
[258]1056_putl(vobj[vobj_id].paddr);
[452]1057_puts(" / value  = ");
[309]1058_putx(vobj[vobj_id].init);
1059_puts("\n");
1060#endif
[452]1061                unsigned int* addr = (unsigned int *) vobj[vobj_id].vbase;
1062                *addr = vobj[vobj_id].init;
1063            }
1064        }
1065    }
[258]1066} // end boot_vobjs_init()
1067
1068///////////////////////////////////////////////////////////////////////////////
1069// This function returns in the vbase and length buffers the virtual base
1070// address and the length of the  segment allocated to the schedulers array
1071// in the cluster defined by the clusterid argument.
1072///////////////////////////////////////////////////////////////////////////////
1073void boot_get_sched_vaddr( unsigned int  cluster_id,
1074                           unsigned int* vbase, 
1075                           unsigned int* length )
1076{
[321]1077    mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
[258]1078    mapping_vobj_t*   vobj   = _get_vobj_base(header);
1079    mapping_vseg_t*   vseg   = _get_vseg_base(header);
1080    mapping_pseg_t*   pseg   = _get_pseg_base(header);
1081
1082    unsigned int vseg_id;
1083    unsigned int found = 0;
1084
1085    for ( vseg_id = 0 ; (vseg_id < header->vsegs) && (found == 0) ; vseg_id++ )
1086    {
1087        if ( (vobj[vseg[vseg_id].vobj_offset].type == VOBJ_TYPE_SCHED) && 
[263]1088             (pseg[vseg[vseg_id].psegid].clusterid == cluster_id ) )
[258]1089        {
1090            *vbase  = vseg[vseg_id].vbase;
1091            *length = vobj[vseg[vseg_id].vobj_offset].length;
1092            found = 1;
1093        }
1094    }
1095    if ( found == 0 )
1096    {
[263]1097        mapping_cluster_t* cluster = _get_cluster_base(header);
1098        _puts("\n[BOOT ERROR] No vobj of type SCHED in cluster [");
1099        _putd( cluster[cluster_id].x );
1100        _puts(",");
1101        _putd( cluster[cluster_id].y );
1102        _puts("]\n");
[258]1103        _exit();
1104    }
1105} // end boot_get_sched_vaddr()
1106
1107////////////////////////////////////////////////////////////////////////////////////
1108// This function initialises all processors schedulers.
1109// This is done by processor 0, and the MMU must be activated.
[412]1110// - In Step 1, it initialises the _schedulers[x][y][l] pointers array, and scan
1111//              the processors for a first initialisation of the schedulers:
1112//              idle_task context, and HWI / SWI / PTI vectors.
[321]1113// - In Step 2, it scan all tasks in all vspaces to complete the tasks contexts,
1114//              initialisation as specified in the mapping_info data structure.
[258]1115////////////////////////////////////////////////////////////////////////////////////
1116void boot_schedulers_init() 
1117{
[321]1118    mapping_header_t*  header  = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
[258]1119    mapping_cluster_t* cluster = _get_cluster_base(header);
1120    mapping_vspace_t*  vspace  = _get_vspace_base(header);
1121    mapping_task_t*    task    = _get_task_base(header);
1122    mapping_vobj_t*    vobj    = _get_vobj_base(header);
[295]1123    mapping_periph_t*  periph  = _get_periph_base(header);
[258]1124    mapping_irq_t*     irq     = _get_irq_base(header);
1125
1126    unsigned int cluster_id;    // cluster index in mapping_info
[295]1127    unsigned int periph_id;     // peripheral index in mapping_info
[258]1128    unsigned int irq_id;        // irq index in mapping_info
1129    unsigned int vspace_id;     // vspace index in mapping_info
1130    unsigned int task_id;       // task index in mapping_info
[321]1131    unsigned int vobj_id;       // vobj index in mapping_info
[258]1132
[321]1133    unsigned int lpid;          // local processor index (for several loops)
1134
[436]1135    // WTI allocators to processors (for HWIs translated to WTIs) 
1136    // In all clusters the first NB_PROCS_MAX WTIs are reserved for WAKUP
[321]1137    unsigned int alloc_wti_channel[X_SIZE*Y_SIZE];   // one per cluster
[258]1138
[321]1139    // pointers on the XCU and PIC peripherals
1140    mapping_periph_t*  xcu = NULL;
1141    mapping_periph_t*  pic = NULL;
1142
[412]1143    unsigned int          sched_vbase;  // schedulers array vbase address in a cluster
1144    unsigned int          sched_length; // schedulers array length
1145    static_scheduler_t*   psched;       // pointer on processor scheduler
[321]1146
[258]1147    /////////////////////////////////////////////////////////////////////////
1148    // Step 1 : loop on the clusters and on the processors
1149    //          to initialize the schedulers[] array of pointers,
[412]1150    //          idle task context and interrupt vectors.
[258]1151    // Implementation note:
[347]1152    // We need to use both (proc_id) to scan the mapping info structure,
1153    // and (x,y,lpid) to access the schedulers array.
[258]1154
[263]1155    for (cluster_id = 0 ; cluster_id < X_SIZE*Y_SIZE ; cluster_id++) 
[258]1156    {
[263]1157        unsigned int x          = cluster[cluster_id].x;
1158        unsigned int y          = cluster[cluster_id].y;
[258]1159
1160#if BOOT_DEBUG_SCHED
[263]1161_puts("\n[BOOT DEBUG] Initialise schedulers in cluster[");
1162_putd( x );
1163_puts(",");
1164_putd( y );
1165_puts("]\n");
[258]1166#endif
[321]1167        alloc_wti_channel[cluster_id] = NB_PROCS_MAX;
[258]1168
1169        // checking processors number
[295]1170        if ( cluster[cluster_id].procs > NB_PROCS_MAX )
[258]1171        {
[263]1172            _puts("\n[BOOT ERROR] Too much processors in cluster[");
1173            _putd( x );
1174            _puts(",");
1175            _putd( y );
1176            _puts("]\n");
[258]1177            _exit();
1178        }
1179 
[295]1180        // no schedulers initialisation if nprocs == 0
1181        if ( cluster[cluster_id].procs > 0 )
[258]1182        {
[412]1183            // get scheduler array virtual base address in cluster[cluster_id]
[295]1184            boot_get_sched_vaddr( cluster_id, &sched_vbase, &sched_length );
[258]1185
[412]1186            if ( sched_length < (cluster[cluster_id].procs<<13) ) // 8 Kbytes per scheduler
[295]1187            {
1188                _puts("\n[BOOT ERROR] Schedulers segment too small in cluster[");
1189                _putd( x );
1190                _puts(",");
1191                _putd( y );
1192                _puts("]\n");
1193                _exit();
1194            }
[263]1195
[436]1196            // scan peripherals to find the XCU and the PIC component
[321]1197
1198            xcu = NULL; 
[295]1199            for ( periph_id = cluster[cluster_id].periph_offset ;
1200                  periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;
1201                  periph_id++ )
1202            {
[436]1203                if( periph[periph_id].type == PERIPH_TYPE_XCU ) 
[295]1204                {
[321]1205                    xcu = &periph[periph_id];
1206
1207                    if ( xcu->arg < cluster[cluster_id].procs )
1208                    {
1209                        _puts("\n[BOOT ERROR] Not enough inputs for XCU[");
1210                        _putd( x );
1211                        _puts(",");
1212                        _putd( y );
1213                        _puts("]\n");
1214                        _exit();
1215                    }
[295]1216                }
[321]1217                if( periph[periph_id].type == PERIPH_TYPE_PIC )   
1218                {
1219                    pic = &periph[periph_id];
1220                }
[295]1221            } 
[321]1222            if ( xcu == NULL )
[295]1223            {         
[436]1224                _puts("\n[BOOT ERROR] No XCU component in cluster[");
[295]1225                _putd( x );
1226                _puts(",");
1227                _putd( y );
1228                _puts("]\n");
1229                _exit();
1230            }
1231
[412]1232            // loop on processors for schedulers default values
[321]1233            // initialisation, including WTI and PTI vectors
[295]1234            for ( lpid = 0 ; lpid < cluster[cluster_id].procs ; lpid++ )
1235            {
[412]1236                // pointer on processor scheduler
1237                psched = (static_scheduler_t*)(sched_vbase + (lpid<<13));
[295]1238
[412]1239                // initialise the schedulers pointers array
1240                _schedulers[x][y][lpid] = psched;
1241
[258]1242#if BOOT_DEBUG_SCHED
[412]1243unsigned int   sched_vbase = (unsigned int)_schedulers[x][y][lpid];
1244unsigned int   sched_ppn;
1245unsigned int   sched_flags;
1246paddr_t        sched_pbase;
1247
1248page_table_t* ptab = (page_table_t*)(_ptabs_vaddr[0][x][y]);
1249_v2p_translate( ptab, sched_vbase>>12, &sched_ppn, &sched_flags );
1250sched_pbase = ((paddr_t)sched_ppn)<<12;
1251
[295]1252_puts("\nProc[");
[263]1253_putd( x );
[295]1254_puts(",");
[263]1255_putd( y );
[295]1256_puts(",");
[263]1257_putd( lpid );
[412]1258_puts("] : scheduler vbase = ");
1259_putx( sched_vbase );
1260_puts(" : scheduler pbase = ");
1261_putl( sched_pbase );
[258]1262_puts("\n");
1263#endif
[295]1264                // initialise the "tasks" and "current" variables default values
[412]1265                psched->tasks   = 0;
1266                psched->current = IDLE_TASK_INDEX;
[258]1267
[321]1268                // default values for HWI / PTI / SWI vectors (valid bit = 0)
[295]1269                unsigned int slot;
1270                for (slot = 0; slot < 32; slot++)
1271                {
[412]1272                    psched->hwi_vector[slot] = 0;
1273                    psched->pti_vector[slot] = 0;
1274                    psched->wti_vector[slot] = 0;
[295]1275                }
[258]1276
[321]1277                // WTI[lpid] <= ISR_WAKUP / PTI[lpid] <= ISR_TICK
[412]1278                psched->wti_vector[lpid] = ISR_WAKUP | 0x80000000;
1279                psched->pti_vector[lpid] = ISR_TICK  | 0x80000000;
[321]1280
[295]1281                // initializes the idle_task context in scheduler:
1282                // - the SR slot is 0xFF03 because this task run in kernel mode.
1283                // - it uses the page table of vspace[0]
1284                // - it uses the kernel TTY terminal
[392]1285                // - slots containing addresses (SP, RA, EPC)
1286                //   must be initialised by kernel_init()
[258]1287
[412]1288                psched->context[IDLE_TASK_INDEX][CTX_CR_ID]   = 0;
1289                psched->context[IDLE_TASK_INDEX][CTX_SR_ID]   = 0xFF03;
1290                psched->context[IDLE_TASK_INDEX][CTX_PTPR_ID] = _ptabs_paddr[0][x][y]>>13;
1291                psched->context[IDLE_TASK_INDEX][CTX_PTAB_ID] = _ptabs_vaddr[0][x][y];
1292                psched->context[IDLE_TASK_INDEX][CTX_TTY_ID]  = 0;
1293                psched->context[IDLE_TASK_INDEX][CTX_LTID_ID] = IDLE_TASK_INDEX;
1294                psched->context[IDLE_TASK_INDEX][CTX_VSID_ID] = 0;
1295                psched->context[IDLE_TASK_INDEX][CTX_RUN_ID]  = 1;
1296
[321]1297            }  // end for processors
[258]1298
[321]1299            // scan HWIs connected to local XCU
1300            // for round-robin allocation to processors
1301            lpid = 0;
1302            for ( irq_id = xcu->irq_offset ;
1303                  irq_id < xcu->irq_offset + xcu->irqs ;
[295]1304                  irq_id++ )
[258]1305            {
[321]1306                unsigned int type    = irq[irq_id].srctype;
1307                unsigned int srcid   = irq[irq_id].srcid;
1308                unsigned int isr     = irq[irq_id].isr & 0xFFFF;
1309                unsigned int channel = irq[irq_id].channel << 16;
1310
1311                if ( (type != IRQ_TYPE_HWI) || (srcid > 31) )
[295]1312                {
[321]1313                    _puts("\n[BOOT ERROR] Bad IRQ in XCU of cluster[");
[295]1314                    _putd( x );
1315                    _puts(",");
1316                    _putd( y );
1317                    _puts("]\n");
1318                    _exit();
1319                }
[258]1320
[412]1321                _schedulers[x][y][lpid]->hwi_vector[srcid] = isr | channel | 0x80000000;
[321]1322                lpid = (lpid + 1) % cluster[cluster_id].procs; 
[258]1323
[321]1324            } // end for irqs
1325        } // end if nprocs > 0
1326    } // end for clusters
[258]1327
[321]1328    // If there is an external PIC component, we scan HWIs connected to PIC
1329    // for Round Robin allocation (as WTI) to processors.
1330    // We allocate one WTI per processor, starting from proc[0,0,0],
1331    // and we increment (cluster_id, lpid) as required.
1332    if ( pic != NULL )
1333    {   
1334        unsigned int cluster_id = 0;   // index in clusters array
1335        unsigned int lpid       = 0;   // processor local index
1336
1337        // scan IRQS defined in PIC
1338        for ( irq_id = pic->irq_offset ;
1339              irq_id < pic->irq_offset + pic->irqs ;
1340              irq_id++ )
1341        {
1342            // compute next values for (cluster_id,lpid)
1343            // if no more procesor available in current cluster
1344            unsigned int overflow = 0;
1345            while ( (lpid >= cluster[cluster_id].procs) ||
1346                    (alloc_wti_channel[cluster_id] >= xcu->arg) )
1347            {
1348                overflow++;
1349                cluster_id = (cluster_id + 1) % (X_SIZE*Y_SIZE);
1350                lpid       = 0;
1351
1352                // overflow detection
1353                if ( overflow > (X_SIZE*Y_SIZE*NB_PROCS_MAX*32) )
1354                {
1355                    _puts("\n[BOOT ERROR] Not enough processors for external IRQs\n");
1356                    _exit();
1357                }
[460]1358            } // end while
[321]1359
1360            unsigned int type    = irq[irq_id].srctype;
1361            unsigned int srcid   = irq[irq_id].srcid;
1362            unsigned int isr     = irq[irq_id].isr & 0xFFFF;
1363            unsigned int channel = irq[irq_id].channel << 16;
1364
1365            if ( (type != IRQ_TYPE_HWI) || (srcid > 31) )
1366            {
1367                _puts("\n[BOOT ERROR] Bad IRQ in PIC component\n");
1368                _exit();
1369            }
1370
1371            // get scheduler[cluster_id] address
1372            unsigned int x          = cluster[cluster_id].x;
1373            unsigned int y          = cluster[cluster_id].y;
1374            unsigned int cluster_xy = (x<<Y_WIDTH) + y;
[412]1375            psched                  = _schedulers[x][y][lpid];
[321]1376
1377            // update WTI vector for scheduler[cluster_id][lpid]
[412]1378            unsigned int index            = alloc_wti_channel[cluster_id];
1379            psched->wti_vector[index]     = isr | channel | 0x80000000;
[460]1380
1381            // increment pointers
[321]1382            alloc_wti_channel[cluster_id] = index + 1;
[412]1383            lpid                          = lpid + 1;
[321]1384
1385            // update IRQ fields in mapping for PIC initialisation
1386            irq[irq_id].dest_id = index;
1387            irq[irq_id].dest_xy = cluster_xy;
1388
1389        }  // end for IRQs
1390    } // end if PIC
1391               
[258]1392#if BOOT_DEBUG_SCHED
[321]1393for ( cluster_id = 0 ; cluster_id < (X_SIZE*Y_SIZE) ; cluster_id++ )
1394{
1395    unsigned int x          = cluster[cluster_id].x;
1396    unsigned int y          = cluster[cluster_id].y;
1397    unsigned int slot;
1398    unsigned int entry;
1399    for ( lpid = 0 ; lpid < cluster[cluster_id].procs ; lpid++ )
1400    {
[412]1401        psched = _schedulers[x][y][lpid];
1402       
[321]1403        _puts("\n*** IRQS for proc[");
1404        _putd( x );
1405        _puts(",");
1406        _putd( y );
[329]1407        _puts(",");
[321]1408        _putd( lpid );
1409        _puts("]\n");
1410        for ( slot = 0 ; slot < 32 ; slot++ )
1411        {
[412]1412            entry = psched->hwi_vector[slot];
[321]1413            if ( entry & 0x80000000 ) 
1414            {
1415                _puts(" - HWI ");
1416                _putd( slot );
1417                _puts(" / isrtype = ");
1418                _putd( entry & 0xFFFF ); 
1419                _puts(" / channel = ");
1420                _putd( (entry >> 16) & 0x7FFF ); 
1421                _puts("\n");
1422            }
1423        }
1424        for ( slot = 0 ; slot < 32 ; slot++ )
1425        {
[412]1426            entry = psched->wti_vector[slot];
[321]1427            if ( entry & 0x80000000 ) 
1428            {
1429                _puts(" - WTI ");
1430                _putd( slot );
1431                _puts(" / isrtype = ");
1432                _putd( entry & 0xFFFF ); 
1433                _puts(" / channel = ");
1434                _putd( (entry >> 16) & 0x7FFF ); 
1435                _puts("\n");
1436            }
1437        }
1438        for ( slot = 0 ; slot < 32 ; slot++ )
1439        {
[412]1440            entry = psched->pti_vector[slot];
[321]1441            if ( entry & 0x80000000 ) 
1442            {
1443                _puts(" - PTI ");
1444                _putd( slot );
1445                _puts(" / isrtype = ");
1446                _putd( entry & 0xFFFF ); 
1447                _puts(" / channel = ");
1448                _putd( (entry >> 16) & 0x7FFF ); 
1449                _puts("\n");
1450            }
1451        }
1452    }
1453}
[258]1454#endif
1455
1456    ///////////////////////////////////////////////////////////////////
[295]1457    // Step 2 : loop on the vspaces and the tasks  to complete
1458    //          the schedulers and task contexts initialisation.
[258]1459
1460    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
1461    {
1462        // We must set the PTPR depending on the vspace, because the start_vector
1463        // and the stack address are defined in virtual space.
[347]1464        _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[vspace_id][0][0] >> 13) );
[258]1465
[412]1466        // loop on the tasks in vspace (task_id is the global index in mapping)
[258]1467        for (task_id = vspace[vspace_id].task_offset;
1468             task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
1469             task_id++) 
1470        {
[295]1471            // compute the cluster coordinates & local processor index
[263]1472            unsigned int x          = cluster[task[task_id].clusterid].x;
1473            unsigned int y          = cluster[task[task_id].clusterid].y;
1474            unsigned int cluster_xy = (x<<Y_WIDTH) + y;
[295]1475            unsigned int lpid       = task[task_id].proclocid;                 
[263]1476
[258]1477#if BOOT_DEBUG_SCHED
1478_puts("\n[BOOT DEBUG] Initialise context for task ");
1479_puts( task[task_id].name );
1480_puts(" in vspace ");
1481_puts( vspace[vspace_id].name );
[309]1482_puts("\n");
[258]1483#endif
1484            // compute gpid (global processor index) and scheduler base address
[427]1485            unsigned int gpid = (cluster_xy << P_WIDTH) + lpid;
[347]1486            psched            = _schedulers[x][y][lpid];
[258]1487
1488            // ctx_sr : value required before an eret instruction
1489            unsigned int ctx_sr = 0x0000FF13;
1490
1491            // ctx_ptpr : page table physical base address (shifted by 13 bit)
[347]1492            unsigned int ctx_ptpr = (unsigned int)(_ptabs_paddr[vspace_id][x][y] >> 13);
[258]1493
1494            // ctx_ptab : page_table virtual base address
[412]1495            unsigned int ctx_ptab = _ptabs_vaddr[vspace_id][x][y];
[258]1496
1497            // ctx_epc : Get the virtual address of the memory location containing
1498            // the task entry point : the start_vector is stored by GCC in the seg_data
1499            // segment and we must wait the .elf loading to get the entry point value...
[321]1500            vobj_id = vspace[vspace_id].start_vobj_id;     
[412]1501            unsigned int ctx_epc = vobj[vobj_id].vbase + (task[task_id].startid)*4;
[258]1502
1503            // ctx_sp :  Get the vobj containing the stack
[321]1504            vobj_id = task[task_id].stack_vobj_id;
[412]1505            unsigned int ctx_sp = vobj[vobj_id].vbase + vobj[vobj_id].length;
[258]1506
1507            // get local task index in scheduler
1508            unsigned int ltid = psched->tasks;
1509
[267]1510            // get vspace thread index
1511            unsigned int thread_id = task[task_id].trdid;
1512
[258]1513            if (ltid >= IDLE_TASK_INDEX) 
1514            {
1515                _puts("\n[BOOT ERROR] in boot_schedulers_init() : ");
1516                _putd( ltid );
1517                _puts(" tasks allocated to processor ");
1518                _putd( gpid );
1519                _puts(" / max is ");
1520                _putd( IDLE_TASK_INDEX );
1521                _puts("\n");
1522                _exit();
1523            }
1524
1525            // update the "tasks" and "current" fields in scheduler:
1526            // the first task to execute is task 0 as soon as there is at least
1527            // one task allocated to processor.
1528            psched->tasks   = ltid + 1;
1529            psched->current = 0;
1530
[436]1531            // initializes the task context
[452]1532            psched->context[ltid][CTX_CR_ID]     = 0;
1533            psched->context[ltid][CTX_SR_ID]     = ctx_sr;
1534            psched->context[ltid][CTX_SP_ID]     = ctx_sp;
1535            psched->context[ltid][CTX_EPC_ID]    = ctx_epc;
1536            psched->context[ltid][CTX_PTPR_ID]   = ctx_ptpr;
1537            psched->context[ltid][CTX_PTAB_ID]   = ctx_ptab;
1538            psched->context[ltid][CTX_LTID_ID]   = ltid;
1539            psched->context[ltid][CTX_GTID_ID]   = task_id;
1540            psched->context[ltid][CTX_TRDID_ID]  = thread_id;
1541            psched->context[ltid][CTX_VSID_ID]   = vspace_id;
1542            psched->context[ltid][CTX_RUN_ID]    = 1;
[258]1543
[452]1544            psched->context[ltid][CTX_TTY_ID]    = 0xFFFFFFFF;
1545            psched->context[ltid][CTX_CMA_FB_ID] = 0xFFFFFFFF;
1546            psched->context[ltid][CTX_CMA_RX_ID] = 0xFFFFFFFF;
1547            psched->context[ltid][CTX_CMA_TX_ID] = 0xFFFFFFFF;
1548            psched->context[ltid][CTX_NIC_RX_ID] = 0xFFFFFFFF;
1549            psched->context[ltid][CTX_NIC_TX_ID] = 0xFFFFFFFF;
1550            psched->context[ltid][CTX_TIM_ID]    = 0xFFFFFFFF;
1551            psched->context[ltid][CTX_HBA_ID]    = 0xFFFFFFFF;
[436]1552
[258]1553#if BOOT_DEBUG_SCHED
1554_puts("\nTask ");
1555_putd( task_id );
[295]1556_puts(" allocated to processor[");
[309]1557_putd( x );
[295]1558_puts(",");
[309]1559_putd( y );
[295]1560_puts(",");
[309]1561_putd( lpid );
[295]1562_puts("]\n  - ctx[LTID]   = ");
[258]1563_putd( psched->context[ltid][CTX_LTID_ID] );
1564_puts("\n  - ctx[SR]     = ");
1565_putx( psched->context[ltid][CTX_SR_ID] );
1566_puts("\n  - ctx[SP]     = ");
1567_putx( psched->context[ltid][CTX_SP_ID] );
1568_puts("\n  - ctx[EPC]    = ");
1569_putx( psched->context[ltid][CTX_EPC_ID] );
1570_puts("\n  - ctx[PTPR]   = ");
1571_putx( psched->context[ltid][CTX_PTPR_ID] );
1572_puts("\n  - ctx[PTAB]   = ");
1573_putx( psched->context[ltid][CTX_PTAB_ID] );
1574_puts("\n  - ctx[GTID]   = ");
[295]1575_putx( psched->context[ltid][CTX_GTID_ID] );
[258]1576_puts("\n  - ctx[VSID]   = ");
[295]1577_putx( psched->context[ltid][CTX_VSID_ID] );
[267]1578_puts("\n  - ctx[TRDID]  = ");
[295]1579_putx( psched->context[ltid][CTX_TRDID_ID] );
[258]1580_puts("\n");
1581#endif
1582
1583        } // end loop on tasks
1584    } // end loop on vspaces
[412]1585} // end boot_schedulers_init()
[258]1586
1587//////////////////////////////////////////////////////////////////////////////////
1588// This function loads the map.bin file from block device.
1589//////////////////////////////////////////////////////////////////////////////////
1590void boot_mapping_init()
1591{
[347]1592    // desactivates IOC interrupt
[289]1593    _ioc_init( 0 );
[258]1594
[347]1595    // open file "map.bin"
[295]1596    int fd_id = _fat_open( IOC_BOOT_MODE,
[258]1597                           "map.bin",
1598                           0 );         // no creation
1599    if ( fd_id == -1 )
1600    {
1601        _puts("\n[BOOT ERROR] : map.bin file not found \n");
1602        _exit();
1603    }
1604
1605#if BOOT_DEBUG_MAPPING
1606_puts("\n[BOOT] map.bin file successfully open at cycle ");
1607_putd(_get_proctime());
1608_puts("\n");
1609#endif
1610
[412]1611    // get "map.bin" file size (from fat) and check it
[258]1612    unsigned int size    = fat.fd[fd_id].file_size;
[347]1613
1614    if ( size > SEG_BOOT_MAPPING_SIZE )
1615    {
1616        _puts("\n[BOOT ERROR] : allocated segment too small for map.bin file\n");
1617        _exit();
1618    }
1619
1620    // load "map.bin" file into buffer
[258]1621    unsigned int nblocks = size >> 9;
1622    unsigned int offset  = size & 0x1FF;
1623    if ( offset ) nblocks++;
1624
[295]1625    unsigned int ok = _fat_read( IOC_BOOT_MODE,
[258]1626                                 fd_id, 
[321]1627                                 (unsigned int*)SEG_BOOT_MAPPING_BASE, 
[258]1628                                 nblocks,       
1629                                 0 );      // offset
1630    if ( ok == -1 )
1631    {
1632        _puts("\n[BOOT ERROR] : unable to load map.bin file \n");
1633        _exit();
1634    }
1635    _fat_close( fd_id );
1636   
[347]1637    // close file "map.bin"
[258]1638    boot_mapping_check();
[347]1639
[258]1640} // end boot_mapping_init()
1641
1642
[347]1643/////////////////////////////////////////////////////////////////////////////////////
1644// This function load all loadable segments for one .elf file, identified
1645// by the "pathname" argument. Some loadable segments can be copied in several
1646// clusters: same virtual address but different physical addresses. 
1647// - It open the file.
[359]1648// - It loads the complete file in the dedicated boot_elf_buffer.
1649// - It copies each loadable segments  at the virtual address defined in
1650//   the .elf file, making several copies if the target vseg is not local.
[347]1651// - It closes the file.
[359]1652// This function is supposed to be executed by processor[0,0,0].
[347]1653// Note:
1654//   We must use physical addresses to reach the destination buffers that
1655//   can be located in remote clusters. We use either a _physical_memcpy(),
1656//   or a _dma_physical_copy() if DMA is available.
1657//////////////////////////////////////////////////////////////////////////////////////
1658void load_one_elf_file( unsigned int is_kernel,     // kernel file if non zero
[258]1659                        char*        pathname,
[347]1660                        unsigned int vspace_id )    // to scan the proper vspace
[258]1661{
[347]1662    mapping_header_t  * header  = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
1663    mapping_vspace_t  * vspace  = _get_vspace_base(header);
1664    mapping_vseg_t    * vseg    = _get_vseg_base(header);
1665    mapping_vobj_t    * vobj    = _get_vobj_base(header);
1666
[258]1667    unsigned int seg_id;
1668
1669#if BOOT_DEBUG_ELF
1670_puts("\n[BOOT DEBUG] Start searching file ");
1671_puts( pathname );
1672_puts(" at cycle ");
1673_putd( _get_proctime() );
1674_puts("\n");
1675#endif
1676
1677    // open .elf file
[347]1678    int fd_id = _fat_open( IOC_BOOT_MODE,
[258]1679                           pathname,
1680                           0 );      // no creation
1681    if ( fd_id < 0 )
1682    {
1683        _puts("\n[BOOT ERROR] load_one_elf_file() : ");
1684        _puts( pathname );
1685        _puts(" not found\n");
1686        _exit();
1687    }
1688
[359]1689    // check buffer size versus file size
1690    if ( fat.fd[fd_id].file_size > GIET_ELF_BUFFER_SIZE )
[258]1691    {
[460]1692        _puts("\n[BOOT ERROR] in load_one_elf_file() : ");
[258]1693        _puts( pathname );
[460]1694        _puts(" size = ");
1695        _putx( fat.fd[fd_id].file_size );
1696        _puts("\n exceeds the GIET_ELF_BUFFERSIZE = ");
1697        _putx( GIET_ELF_BUFFER_SIZE );
1698        _puts("\n");
[258]1699        _exit();
1700    }
1701
1702    // compute number of sectors
1703    unsigned int nbytes   = fat.fd[fd_id].file_size;
1704    unsigned int nsectors = nbytes>>9;
1705    if( nbytes & 0x1FF) nsectors++;
1706
[359]1707    // load file in elf buffer
[347]1708    if( _fat_read( IOC_BOOT_MODE, 
[258]1709                   fd_id, 
[359]1710                   boot_elf_buffer,
[258]1711                   nsectors,
1712                   0 ) != nsectors )
1713    {
1714        _puts("\n[BOOT ERROR] load_one_elf_file() : unexpected EOF for file ");
1715        _puts( pathname );
1716        _puts("\n");   
1717        _exit();
1718    }
1719
1720    // Check ELF Magic Number in ELF header
[359]1721    Elf32_Ehdr* elf_header_ptr = (Elf32_Ehdr*)boot_elf_buffer;
[258]1722
1723    if ( (elf_header_ptr->e_ident[EI_MAG0] != ELFMAG0) ||
1724         (elf_header_ptr->e_ident[EI_MAG1] != ELFMAG1) ||
1725         (elf_header_ptr->e_ident[EI_MAG2] != ELFMAG2) ||
1726         (elf_header_ptr->e_ident[EI_MAG3] != ELFMAG3) )
1727    {
1728        _puts("\n[BOOT ERROR] load_elf() : file ");
1729        _puts( pathname );
1730        _puts(" does not use ELF format\n");   
1731        _exit();
1732    }
1733
1734    // get program header table pointer
1735    unsigned int pht_index = elf_header_ptr->e_phoff;
1736    if( pht_index == 0 )
1737    {
1738        _puts("\n[BOOT ERROR] load_one_elf_file() : file ");
1739        _puts( pathname );
1740        _puts(" does not contain loadable segment\n");   
1741        _exit();
1742    }
[359]1743    Elf32_Phdr* elf_pht_ptr = (Elf32_Phdr*)(boot_elf_buffer + pht_index);
[258]1744
1745    // get number of segments
1746    unsigned int nsegments   = elf_header_ptr->e_phnum;
1747
[347]1748    _puts("\n[BOOT] File ");
1749    _puts( pathname );
1750    _puts(" loaded at cycle ");
1751    _putd( _get_proctime() );
1752    _puts("\n");
[258]1753
[347]1754    // Loop on loadable segments in the .elf file
[258]1755    for (seg_id = 0 ; seg_id < nsegments ; seg_id++)
1756    {
1757        if(elf_pht_ptr[seg_id].p_type == PT_LOAD)
1758        {
1759            // Get segment attributes
1760            unsigned int seg_vaddr  = elf_pht_ptr[seg_id].p_vaddr;
1761            unsigned int seg_offset = elf_pht_ptr[seg_id].p_offset;
1762            unsigned int seg_filesz = elf_pht_ptr[seg_id].p_filesz;
1763            unsigned int seg_memsz  = elf_pht_ptr[seg_id].p_memsz;
1764
[347]1765#if BOOT_DEBUG_ELF
1766_puts(" - segment ");
1767_putd( seg_id );
1768_puts(" / vaddr = ");
1769_putx( seg_vaddr );
1770_puts(" / file_size = ");
1771_putx( seg_filesz );
1772_puts("\n");
1773#endif
1774
[258]1775            if( seg_memsz < seg_filesz )
1776            {
1777                _puts("\n[BOOT ERROR] load_one_elf_file() : segment at vaddr = ");
1778                _putx( seg_vaddr );
1779                _puts(" in file ");
1780                _puts( pathname );
[359]1781                _puts(" has memsz < filesz \n");   
[258]1782                _exit();
1783            }
1784
1785            // fill empty space with 0 as required
1786            if( seg_memsz > seg_filesz )
1787            {
1788                unsigned int i; 
[359]1789                for( i = seg_filesz ; i < seg_memsz ; i++ ) boot_elf_buffer[i+seg_offset] = 0;
[258]1790            } 
1791
[359]1792            unsigned int src_vaddr = (unsigned int)boot_elf_buffer + seg_offset;
[258]1793
[347]1794            // search all vsegs matching the virtual address
1795            unsigned int vseg_first;
1796            unsigned int vseg_last;
1797            unsigned int vseg_id;
1798            unsigned int found = 0;
1799            if ( is_kernel )
1800            {
1801                vseg_first = 0;
1802                vseg_last  = header->globals;
1803            }
1804            else
1805            {
1806                vseg_first = vspace[vspace_id].vseg_offset;
1807                vseg_last  = vseg_first + vspace[vspace_id].vsegs;
1808            }
1809
1810            for ( vseg_id = vseg_first ; vseg_id < vseg_last ; vseg_id++ )
1811            {
1812                if ( seg_vaddr == vseg[vseg_id].vbase )  // matching
1813                {
1814                    found = 1;
1815
1816                    // get destination buffer physical address and size
1817                    paddr_t      seg_paddr  = vseg[vseg_id].pbase;
1818                    unsigned int vobj_id    = vseg[vseg_id].vobj_offset;
1819                    unsigned int seg_size   = vobj[vobj_id].length;
1820                   
[258]1821#if BOOT_DEBUG_ELF
[347]1822_puts("   loaded into vseg ");
1823_puts( vseg[vseg_id].name );
1824_puts(" at paddr = ");
1825_putl( seg_paddr );
1826_puts(" (buffer size = ");
1827_putx( seg_size );
1828_puts(")\n");
[258]1829#endif
[347]1830                    // check vseg size
1831                    if ( seg_size < seg_filesz )
1832                    {
1833                        _puts("\n[BOOT ERROR] in load_one_elf_file()\n");
1834                        _puts("vseg ");
1835                        _puts( vseg[vseg_id].name );
1836                        _puts(" is to small for loadable segment ");
1837                        _putx( seg_vaddr );
1838                        _puts(" in file ");
1839                        _puts( pathname );
1840                        _puts(" \n");   
1841                        _exit();
1842                    }
[258]1843
[347]1844                    // copy the segment from boot buffer to destination buffer
1845                    // using DMA channel[0,0,0] if it is available.
1846                    if( NB_DMA_CHANNELS > 0 )
1847                    {
1848                        _dma_physical_copy( 0,                  // DMA in cluster[0,0]
1849                                            0,                  // DMA channel 0
1850                                            (paddr_t)seg_paddr, // destination paddr
1851                                            (paddr_t)src_vaddr, // source paddr
1852                                            seg_filesz );       // size
1853                    }
1854                    else
1855                    {
1856                        _physical_memcpy( (paddr_t)seg_paddr,   // destination paddr
1857                                          (paddr_t)src_vaddr,   // source paddr
1858                                          seg_filesz );         // size
1859                    }
1860                }
1861            }  // end for vsegs in vspace
1862
1863            // check at least one matching vseg
1864            if ( found == 0 )
[258]1865            {
[347]1866                _puts("\n[BOOT ERROR] in load_one_elf_file()\n");
1867                _puts("vseg for loadable segment ");
1868                _putx( seg_vaddr );
1869                _puts(" in file ");
1870                _puts( pathname );
[436]1871                _puts(" not found: \n");   
1872                _puts(" check consistency between the .py and .ld files...\n");
[347]1873                _exit();
[258]1874            }
1875        }
[347]1876    }  // end for loadable segments
[258]1877
1878    // close .elf file
1879    _fat_close( fd_id );
1880
1881} // end load_one_elf_file()
1882
1883
[347]1884/////i////////////////////////////////////////////////////////////////////////////////
[258]1885// This function uses the map.bin data structure to load the "kernel.elf" file
[347]1886// as well as the various "application.elf" files into memory.
1887// - The "preloader.elf" file is not loaded, because it has been burned in the ROM.
1888// - The "boot.elf" file is not loaded, because it has been loaded by the preloader.
[295]1889// This function scans all vobjs defined in the map.bin data structure to collect
[347]1890// all .elf files pathnames, and calls the load_one_elf_file() for each .elf file.
1891// As the code can be replicated in several vsegs, the same code can be copied
1892// in one or several clusters by the load_one_elf_file() function.
1893//////////////////////////////////////////////////////////////////////////////////////
[258]1894void boot_elf_load()
1895{
[321]1896    mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
[258]1897    mapping_vspace_t* vspace = _get_vspace_base( header );
1898    mapping_vobj_t*   vobj   = _get_vobj_base( header );
1899    unsigned int      vspace_id;
1900    unsigned int      vobj_id;
1901    unsigned int      found;
1902
1903    // Scan all vobjs corresponding to global vsegs,
1904    // to find the pathname to the kernel.elf file
1905    found = 0;
1906    for( vobj_id = 0 ; vobj_id < header->globals ; vobj_id++ )
1907    {
1908        if(vobj[vobj_id].type == VOBJ_TYPE_ELF) 
1909        {   
1910            found = 1;
1911            break;
1912        }
1913    }
1914
1915    // We need one kernel.elf file
1916    if (found == 0)
1917    {
1918        _puts("[BOOT ERROR] boot_elf_load() : kernel.elf file not found\n");
1919        _exit();
1920    }
1921
[347]1922    // Load the kernel
1923    load_one_elf_file( 1,                           // kernel file
1924                       vobj[vobj_id].binpath,       // file pathname
[258]1925                       0 );                         // vspace 0
1926
[347]1927    // loop on the vspaces, scanning all vobjs in the vspace,
[258]1928    // to find the pathname of the .elf file associated to the vspace.
1929    for( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ )
1930    {
1931        // loop on the vobjs in vspace (vobj_id is the global index)
1932        unsigned int found = 0;
1933        for (vobj_id = vspace[vspace_id].vobj_offset;
1934             vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs);
1935             vobj_id++) 
1936        {
1937            if(vobj[vobj_id].type == VOBJ_TYPE_ELF) 
1938            {   
1939                found = 1;
1940                break;
1941            }
1942        }
1943
1944        // We want one .elf file per vspace
1945        if (found == 0)
1946        {
1947            _puts("[BOOT ERROR] boot_elf_load() : .elf file not found for vspace ");
1948            _puts( vspace[vspace_id].name );
1949            _puts("\n");
1950            _exit();
1951        }
1952
[347]1953        load_one_elf_file( 0,                          // not a kernel file
1954                           vobj[vobj_id].binpath,      // file pathname
1955                           vspace_id );                // vspace index
[258]1956
1957    }  // end for vspaces
1958
1959} // end boot_elf_load()
1960
1961////////////////////////////////////////////////////////////////////////////////
1962// This function intializes the periherals and coprocessors, as specified
1963// in the mapping_info file.
1964////////////////////////////////////////////////////////////////////////////////
1965void boot_peripherals_init() 
1966{
[321]1967    mapping_header_t * header   = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
[258]1968    mapping_cluster_t * cluster = _get_cluster_base(header);
1969    mapping_periph_t * periph   = _get_periph_base(header);
1970    mapping_vobj_t * vobj       = _get_vobj_base(header);
1971    mapping_coproc_t * coproc   = _get_coproc_base(header);
1972    mapping_cp_port_t * cp_port = _get_cp_port_base(header);
[295]1973    mapping_irq_t * irq         = _get_irq_base(header);
[258]1974
1975    unsigned int cluster_id;
1976    unsigned int periph_id;
1977    unsigned int coproc_id;
1978    unsigned int cp_port_id;
1979    unsigned int channel_id;
1980
[263]1981    // loop on all physical clusters
1982    for (cluster_id = 0; cluster_id < X_SIZE*Y_SIZE; cluster_id++) 
[258]1983    {
[263]1984        // computes cluster coordinates
1985        unsigned int x          = cluster[cluster_id].x;
1986        unsigned int y          = cluster[cluster_id].y;
1987        unsigned int cluster_xy = (x<<Y_WIDTH) + y;
[258]1988
1989#if BOOT_DEBUG_PERI
[329]1990_puts("\n[BOOT DEBUG] Peripherals initialisation in cluster[");
[263]1991_putd( x );
1992_puts(",");
1993_putd( y );
[329]1994_puts("]\n");
[258]1995#endif
1996
[263]1997        // loop on peripherals
[258]1998        for (periph_id = cluster[cluster_id].periph_offset;
1999             periph_id < cluster[cluster_id].periph_offset +
2000             cluster[cluster_id].periphs; periph_id++) 
2001        {
2002            unsigned int type       = periph[periph_id].type;
[347]2003            unsigned int subtype    = periph[periph_id].subtype;
[258]2004            unsigned int channels   = periph[periph_id].channels;
2005
2006            switch (type) 
2007            {
2008                case PERIPH_TYPE_IOC:    // vci_block_device component
2009                {
[347]2010                    if ( subtype == PERIPH_SUBTYPE_BDV )
[289]2011                    {
[460]2012                        _bdv_init();
[347]2013                    }
[460]2014                    else if ( subtype == PERIPH_SUBTYPE_HBA ) 
[347]2015                    {
[460]2016                        for (channel_id = 0; channel_id < channels; channel_id++) 
2017                            _hba_init( channel_id );
[347]2018                    }
[460]2019                    else if ( subtype == PERIPH_SUBTYPE_SPI ) 
[347]2020                    {
[460]2021                        //TODO
[347]2022                    }
[258]2023                    break;
2024                }
[460]2025                case PERIPH_TYPE_TTY:    // vci_multi_tty component
[263]2026                {
2027                    for (channel_id = 0; channel_id < channels; channel_id++) 
2028                    {
[460]2029                        _tty_init( channel_id );
[263]2030                    }
2031                    break;
2032                }
[258]2033                case PERIPH_TYPE_NIC:    // vci_multi_nic component
2034                {
[460]2035                    _nic_global_init( 1,      // broadcast accepted
2036                                      1,      // bypass activated
2037                                      0,      // tdm non activated
2038                                      0 );    // tdm period
[258]2039                    break;
2040                }
[299]2041                case PERIPH_TYPE_IOB:    // vci_io_bridge component
[258]2042                {
[299]2043                    if (GIET_USE_IOMMU) 
[258]2044                    {
2045                        // TODO
2046                        // get the iommu page table physical address
2047                        // set IOMMU page table address
2048                        // pseg_base[IOB_IOMMU_PTPR] = ptab_pbase;   
2049                        // activate IOMMU
2050                        // pseg_base[IOB_IOMMU_ACTIVE] = 1;       
2051                    }
2052                    break;
2053                }
[295]2054                case PERIPH_TYPE_PIC:    // vci_iopic component
2055                {
[309]2056                    // scan all IRQs defined in mapping for PIC component,
[295]2057                    // and initialises addresses for WTI IRQs
2058                    for ( channel_id = periph[periph_id].irq_offset ;
2059                          channel_id < periph[periph_id].irq_offset + periph[periph_id].irqs ;
2060                          channel_id++ )
2061                    {
[321]2062                        unsigned int hwi_id     = irq[channel_id].srcid;   // HWI index in PIC
2063                        unsigned int wti_id     = irq[channel_id].dest_id; // WTI index in XCU
2064                        unsigned int cluster_xy = irq[channel_id].dest_xy; // XCU coordinates
[295]2065                        unsigned int vaddr;
2066
2067                        _xcu_get_wti_address( wti_id, &vaddr );
[412]2068                        _pic_init( hwi_id, vaddr, cluster_xy ); 
[295]2069
2070#if BOOT_DEBUG_PERI
[412]2071unsigned int address = _pic_get_register( channel_id, IOPIC_ADDRESS );
2072unsigned int extend  = _pic_get_register( channel_id, IOPIC_EXTEND  );
[295]2073_puts("    hwi_index = ");
2074_putd( hwi_id );
2075_puts(" / wti_index = ");
2076_putd( wti_id );
2077_puts(" / vaddr = ");
2078_putx( vaddr );
2079_puts(" in cluster[");
[321]2080_putd( cluster_xy >> Y_WIDTH );
[295]2081_puts(",");
[321]2082_putd( cluster_xy & ((1<<Y_WIDTH)-1) );
[412]2083_puts("] / checked_xcu_paddr = ");
2084_putl( (paddr_t)address + (((paddr_t)extend)<<32) );
2085_puts("\n");
[295]2086#endif
2087                    }
2088                    break;
2089                }
[258]2090            }  // end switch periph type
2091        }  // end for periphs
2092
2093#if BOOT_DEBUG_PERI
[329]2094_puts("\n[BOOT DEBUG] Coprocessors initialisation in cluster[");
[263]2095_putd( x );
2096_puts(",");
2097_putd( y );
[329]2098_puts("]\n");
[258]2099#endif
2100
[263]2101        // loop on coprocessors
[258]2102        for ( coproc_id = cluster[cluster_id].coproc_offset;
2103              coproc_id < cluster[cluster_id].coproc_offset +
2104              cluster[cluster_id].coprocs; coproc_id++ ) 
2105        {
2106
2107#if BOOT_DEBUG_PERI
2108_puts("- coprocessor name : ");
2109_puts(coproc[coproc_id].name);
2110_puts(" / nb ports = ");
2111_putd((unsigned int) coproc[coproc_id].ports);
2112_puts("\n");
2113#endif
2114            // loop on the coprocessor ports
2115            for ( cp_port_id = coproc[coproc_id].port_offset;
2116                  cp_port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports;
2117                  cp_port_id++ ) 
2118            {
[412]2119                // get global index of associted vobj
[321]2120                unsigned int vobj_id   = cp_port[cp_port_id].mwmr_vobj_id; 
[258]2121
[412]2122                // get MWMR channel base address
2123                page_table_t* ptab  = (page_table_t*)_ptabs_vaddr[0][x][y];
2124                unsigned int  vbase = vobj[vobj_id].vbase;
2125                unsigned int  ppn;
2126                unsigned int  flags;
2127                paddr_t       pbase;
[258]2128
[412]2129                _v2p_translate( ptab, 
2130                                vbase>>12 , 
2131                                &ppn, 
2132                                &flags );
2133
2134                pbase = ((paddr_t)ppn)<<12;
2135
2136                // initialise cp_port
[263]2137                _mwr_hw_init( cluster_xy,
2138                              cp_port_id, 
2139                              cp_port[cp_port_id].direction, 
[412]2140                              pbase );
[258]2141#if BOOT_DEBUG_PERI
2142_puts("     port direction: ");
2143_putd( (unsigned int)cp_port[cp_port_id].direction );
2144_puts(" / mwmr_channel_pbase = ");
[412]2145_putl( pbase );
[258]2146_puts(" / name = ");
2147_puts(vobj[vobj_id].name);
2148_puts("\n"); 
2149#endif
2150            } // end for cp_ports
2151        } // end for coprocs
2152    } // end for clusters
2153} // end boot_peripherals_init()
2154
2155/////////////////////////////////////////////////////////////////////////
[412]2156// This function initialises the physical memory allocators in each
2157// cluster containing a RAM pseg.
2158/////////////////////////////////////////////////////////////////////////
2159void boot_pmem_init() 
2160{
2161    mapping_header_t*  header     = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
2162    mapping_cluster_t* cluster    = _get_cluster_base(header);
2163    mapping_pseg_t*    pseg       = _get_pseg_base(header);
2164
2165    unsigned int cluster_id;
2166    unsigned int pseg_id;
2167
2168    // scan all clusters
2169    for ( cluster_id = 0 ; cluster_id < X_SIZE*Y_SIZE ; cluster_id++ ) 
2170    {
2171        // scan the psegs in cluster to find first pseg of type RAM
2172        unsigned int pseg_min = cluster[cluster_id].pseg_offset;
2173        unsigned int pseg_max = pseg_min + cluster[cluster_id].psegs;
2174        for ( pseg_id = pseg_min ; pseg_id < pseg_max ; pseg_id++ )
2175        {
2176            if ( pseg[pseg_id].type == PSEG_TYPE_RAM )
2177            {
2178                unsigned int x    = cluster[cluster_id].x;
2179                unsigned int y    = cluster[cluster_id].y;
2180                unsigned int base = (unsigned int)pseg[pseg_id].base;
2181                unsigned int size = (unsigned int)pseg[pseg_id].length;
2182                _pmem_alloc_init( x, y, base, size );
2183
2184#if BOOT_DEBUG_PT
2185_puts("\n[BOOT DEBUG] pmem allocator initialised in cluster[");
2186_putd( x );
2187_puts(",");
2188_putd( y );
2189_puts("] base = ");
2190_putx( base );
2191_puts(" / size = ");
2192_putx( size );
2193_puts("\n");
2194#endif
2195               break;
2196            }
2197        }
2198    }
2199} // end boot_pmem_init()
2200 
2201/////////////////////////////////////////////////////////////////////////
[258]2202// This function is the entry point of the boot code for all processors.
2203// Most of this code is executed by Processor 0 only.
2204/////////////////////////////////////////////////////////////////////////
[347]2205void boot_init() 
[258]2206{
[321]2207    mapping_header_t*  header     = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
[295]2208    mapping_cluster_t* cluster    = _get_cluster_base(header);
2209    unsigned int       gpid       = _get_procid();
[258]2210 
[263]2211    if ( gpid == 0 )    // only Processor 0 does it
[258]2212    {
2213        _puts("\n[BOOT] boot_init start at cycle ");
2214        _putd(_get_proctime());
2215        _puts("\n");
2216
[460]2217        // initialises the FAT
2218        _fat_init( IOC_BOOT_MODE );
2219
2220        _puts("\n[BOOT] Fat initialised at cycle ");
2221        _putd(_get_proctime());
2222        _puts("\n");
2223
[347]2224        // Load the map.bin file into memory and check it
[258]2225        boot_mapping_init();
2226
[295]2227        _puts("\n[BOOT] Mapping \"");
[258]2228        _puts( header->name );
[295]2229        _puts("\" loaded at cycle ");
[258]2230        _putd(_get_proctime());
2231        _puts("\n");
2232
[412]2233        // Initializes the physical memory allocators
2234        boot_pmem_init();
2235
2236        _puts("\n[BOOT] Physical memory allocators initialised at cycle ");
2237        _putd(_get_proctime());
2238        _puts("\n");
2239
[347]2240        // Build page tables
[436]2241        boot_ptabs_init();
[258]2242
[412]2243        _puts("\n[BOOT] Page tables initialised at cycle ");
2244        _putd(_get_proctime());
2245        _puts("\n");
2246
[347]2247        // Activate MMU for proc [0,0,0]
2248        _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[0][0][0]>>13) );
[258]2249        _set_mmu_mode( 0xF );
2250
[263]2251        _puts("\n[BOOT] Processor[0,0,0] : MMU activation at cycle ");
[258]2252        _putd(_get_proctime());
2253        _puts("\n");
2254
[347]2255        // Initialise private vobjs in vspaces
[258]2256        boot_vobjs_init();
2257
2258        _puts("\n[BOOT] Private vobjs initialised at cycle ");
2259        _putd(_get_proctime());
2260        _puts("\n");
[452]2261 
[347]2262        // Initialise schedulers
[258]2263        boot_schedulers_init();
2264
[295]2265        _puts("\n[BOOT] Schedulers initialised at cycle ");
[258]2266        _putd(_get_proctime());
2267        _puts("\n");
2268       
[347]2269        // Set CP0_SCHED register for proc [0,0,0]
2270        _set_sched( (unsigned int)_schedulers[0][0][0] );
[258]2271
[347]2272        // Initialise non replicated peripherals
[258]2273        boot_peripherals_init();
2274
[295]2275        _puts("\n[BOOT] Non replicated peripherals initialised at cycle ");
[258]2276        _putd(_get_proctime());
2277        _puts("\n");
2278
2279        // Loading all .elf files
2280        boot_elf_load();
2281
[295]2282        // P0 starts all other processors
2283        unsigned int clusterid, p;
[258]2284
[295]2285        for ( clusterid = 0 ; clusterid < X_SIZE*Y_SIZE ; clusterid++ ) 
[258]2286        {
[295]2287            unsigned int nprocs     = cluster[clusterid].procs;
[347]2288            unsigned int x          = cluster[clusterid].x;
2289            unsigned int y          = cluster[clusterid].y;
2290            unsigned int cluster_xy = (x<<Y_WIDTH) + y;
[295]2291
2292            for ( p = 0 ; p < nprocs; p++ ) 
[258]2293            {
[295]2294                if ( (nprocs > 0) && ((clusterid != 0) || (p != 0)) )
[258]2295                {
[366]2296                    _xcu_send_wti( cluster_xy, p, (unsigned int)boot_entry );
[258]2297                }
2298            }
2299        }
[295]2300 
[258]2301    }  // end monoprocessor boot
2302
[356]2303    ///////////////////////////////////////////////////////////////////////////////
2304    //            Parallel execution starts actually here
2305    ///////////////////////////////////////////////////////////////////////////////
2306
2307    // all processor initialise the SCHED register
2308    // from the _schedulers[x][y][lpid array]
[427]2309    unsigned int cluster_xy = gpid >> P_WIDTH;
2310    unsigned int lpid       = gpid & ((1<<P_WIDTH)-1);
[347]2311    unsigned int x          = cluster_xy >> Y_WIDTH;
2312    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
2313    _set_sched( (unsigned int)_schedulers[x][y][lpid] );
[258]2314
[347]2315    // all processors (but Proc[0,0,0]) activate MMU
[263]2316    if ( gpid != 0 )
[258]2317    {
[347]2318        _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[0][x][y]>>13) );
[258]2319        _set_mmu_mode( 0xF );
2320    }
2321
[427]2322    // all processors reset BEV bit in the status register to use
2323    // the GIET_VM exception handler instead of the PRELOADER exception handler
2324    _set_sr( 0 );
2325
[356]2326    // all processors jump to kernel_init
2327    // using the address defined in the giet_vsegs.ld file
[321]2328    unsigned int kernel_entry = (unsigned int)&kernel_init_vbase;
[258]2329    asm volatile( "jr   %0" ::"r"(kernel_entry) );
2330
2331} // end boot_init()
2332
2333
2334// Local Variables:
2335// tab-width: 4
2336// c-basic-offset: 4
2337// c-file-offsets:((innamespace . 0)(inline-open . 0))
2338// indent-tabs-mode: nil
2339// End:
2340// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
2341
Note: See TracBrowser for help on using the repository browser.