source: trunk/kernel/kern/kernel_init.c @ 690

Last change on this file since 690 was 683, checked in by alain, 4 years ago

All modifications required to support the <tcp_chat> application
including error recovery in case of packet loss.A

File size: 65.6 KB
RevLine 
[1]1/*
2 * kernel_init.c - kernel parallel initialization
[127]3 *
[23]4 * Authors :  Mohamed Lamine Karaoui (2015)
[683]5 *            Alain Greiner          (2016,2017,2018,2019,2020)
[1]6 *
7 * Copyright (c) Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2.0 of the License.
14 *
15 * ALMOS-MKH is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
[14]25#include <kernel_config.h>
[1]26#include <errno.h>
[457]27#include <hal_kernel_types.h>
[1]28#include <hal_special.h>
29#include <hal_context.h>
[279]30#include <hal_irqmask.h>
[564]31#include <hal_macros.h>
[296]32#include <hal_ppm.h>
[14]33#include <barrier.h>
[564]34#include <xbarrier.h>
[407]35#include <remote_fifo.h>
[1]36#include <core.h>
37#include <list.h>
[68]38#include <xlist.h>
[204]39#include <xhtab.h>
[1]40#include <thread.h>
41#include <scheduler.h>
[662]42#include <ksocket.h>
[1]43#include <kmem.h>
44#include <cluster.h>
45#include <string.h>
46#include <memcpy.h>
47#include <ppm.h>
[683]48#include <kcm.h>
[1]49#include <page.h>
[5]50#include <chdev.h>
[1]51#include <boot_info.h>
52#include <dqdt.h>
53#include <dev_mmc.h>
[5]54#include <dev_dma.h>
55#include <dev_iob.h>
[1]56#include <dev_ioc.h>
[5]57#include <dev_txt.h>
[1]58#include <dev_pic.h>
59#include <printk.h>
60#include <vfs.h>
[23]61#include <devfs.h>
[68]62#include <mapper.h>
[1]63
64///////////////////////////////////////////////////////////////////////////////////////////
[279]65// All the following global variables are replicated in all clusters.
[1]66// They are initialised by the kernel_init() function.
[14]67//
[127]68// WARNING : The section names have been defined to control the base addresses of the
[14]69// boot_info structure and the idle thread descriptors, through the kernel.ld script:
[127]70// - the boot_info structure is built by the bootloader, and used by kernel_init.
71//   it must be the first object in the kdata segment.
[14]72// - the array of idle threads descriptors must be placed on the first page boundary after
73//   the boot_info structure in the kdata segment.
[1]74///////////////////////////////////////////////////////////////////////////////////////////
75
[5]76// This variable defines the local boot_info structure
77__attribute__((section(".kinfo")))
[14]78boot_info_t          boot_info;
[5]79
[14]80// This variable defines the "idle" threads descriptors array
81__attribute__((section(".kidle")))
[381]82char                 idle_threads[CONFIG_THREAD_DESC_SIZE *
[14]83                                   CONFIG_MAX_LOCAL_CORES]   CONFIG_PPM_PAGE_ALIGNED;
84
[127]85// This variable defines the local cluster manager
[5]86__attribute__((section(".kdata")))
[19]87cluster_t            cluster_manager                         CONFIG_CACHE_LINE_ALIGNED;
[1]88
[564]89// This variable defines the TXT_TX[0] chdev
[188]90__attribute__((section(".kdata")))
[564]91chdev_t              txt0_tx_chdev                           CONFIG_CACHE_LINE_ALIGNED;
[188]92
[564]93// This variable defines the TXT_RX[0] chdev
[539]94__attribute__((section(".kdata")))
[564]95chdev_t              txt0_rx_chdev                           CONFIG_CACHE_LINE_ALIGNED;
[539]96
[14]97// This variables define the kernel process0 descriptor
[5]98__attribute__((section(".kdata")))
[19]99process_t            process_zero                            CONFIG_CACHE_LINE_ALIGNED;
[1]100
[624]101// This variable defines a set of extended pointers on the distributed chdevs
[5]102__attribute__((section(".kdata")))
[14]103chdev_directory_t    chdev_dir                               CONFIG_CACHE_LINE_ALIGNED;
[1]104
[188]105// This variable contains the input IRQ indexes for the IOPIC controller
[5]106__attribute__((section(".kdata")))
[246]107iopic_input_t        iopic_input                             CONFIG_CACHE_LINE_ALIGNED;
[1]108
[188]109// This variable contains the input IRQ indexes for the LAPIC controller
[5]110__attribute__((section(".kdata")))
[188]111lapic_input_t        lapic_input                             CONFIG_CACHE_LINE_ALIGNED;
[1]112
[14]113// This variable defines the local cluster identifier
[5]114__attribute__((section(".kdata")))
[14]115cxy_t                local_cxy                               CONFIG_CACHE_LINE_ALIGNED;
[5]116
[623]117// This variable is used for core[0] cores synchronisation in kernel_init()
[5]118__attribute__((section(".kdata")))
[564]119xbarrier_t           global_barrier                          CONFIG_CACHE_LINE_ALIGNED;
[1]120
[127]121// This variable is used for local cores synchronisation in kernel_init()
[14]122__attribute__((section(".kdata")))
123barrier_t            local_barrier                           CONFIG_CACHE_LINE_ALIGNED;
124
[127]125// This variable defines the array of supported File System contexts
[50]126__attribute__((section(".kdata")))
127vfs_ctx_t            fs_context[FS_TYPES_NR]                 CONFIG_CACHE_LINE_ALIGNED;
128
[564]129// This array is used for debug, and describes the kernel locks usage,
130// It must be kept consistent with the defines in kernel_config.h file.
[624]131__attribute__((section(".kdata")))
[564]132char * lock_type_str[] =
133{
[662]134    "unused_0",              //  0   must be unused to help debug
[408]135
[564]136    "CLUSTER_KCM",           //  1
[632]137    "SCHED_STATE",           //  2
138    "VMM_STACK",             //  3
139    "VMM_MMAP",              //  4
[657]140    "KCM_STATE",             //  5
141    "KHM_STATE",             //  6
142    "HTAB_STATE",            //  7
[669]143    "CORE_ALARMS",           //  8
[564]144
[669]145    "VFS_CTX",               //  9
146    "PPM_FREE",              // 10
147    "THREAD_JOIN",           // 11
148    "XHTAB_STATE",           // 12
149    "CHDEV_QUEUE",           // 13
150    "CHDEV_TXT0",            // 14
151    "CHDEV_TXTLIST",         // 15
152    "PAGE_STATE",            // 16
153    "MUTEX_STATE",           // 17
154    "CONDVAR_STATE",         // 18
155    "SEM_STATE",             // 19
156    "PROCESS_CWD",           // 20
157    "BARRIER_STATE",         // 21
158    "LISTEN_SOCKET",         // 22
[564]159
[669]160    "CLUSTER_PREFTBL",       // 23
[601]161
[669]162    "SOCKET_STATE",          // 24
163    "PPM_DIRTY",             // 25
164    "CLUSTER_LOCALS",        // 26
165    "CLUSTER_COPIES",        // 27
166    "PROCESS_CHILDREN",      // 28
167    "PROCESS_USERSYNC",      // 29
168    "PROCESS_FDARRAY",       // 30
169    "PROCESS_DIR",           // 31
170    "VMM_VSL",               // 32
[564]171
[669]172    "PROCESS_THTBL",         // 33
[564]173
[669]174    "MAPPER_STATE",          // 34
175    "VFS_SIZE",              // 35
176    "VFS_FILE",              // 36
177    "VFS_MAIN",              // 37
178    "FATFS_FAT",             // 38
179    "FBF_WINDOWS",           // 39
[564]180};       
181
[662]182// debug variables to analyse the sys_read()  syscalls timing
[564]183
[438]184#if DEBUG_SYS_READ
[407]185uint32_t   enter_sys_read;
186uint32_t   exit_sys_read;
187
[435]188uint32_t   enter_devfs_read;
189uint32_t   exit_devfs_read;
[407]190
191uint32_t   enter_txt_read;
192uint32_t   exit_txt_read;
193
[435]194uint32_t   enter_chdev_cmd_read;
195uint32_t   exit_chdev_cmd_read;
[407]196
[435]197uint32_t   enter_chdev_server_read;
198uint32_t   exit_chdev_server_read;
[407]199
[435]200uint32_t   enter_tty_cmd_read;
201uint32_t   exit_tty_cmd_read;
[407]202
[435]203uint32_t   enter_tty_isr_read;
204uint32_t   exit_tty_isr_read;
[407]205#endif
206
[662]207// debug variables  to analyse the sys_write() syscall timing
[435]208
[438]209#if DEBUG_SYS_WRITE   
[435]210uint32_t   enter_sys_write;
211uint32_t   exit_sys_write;
212
213uint32_t   enter_devfs_write;
214uint32_t   exit_devfs_write;
215
216uint32_t   enter_txt_write;
217uint32_t   exit_txt_write;
218
219uint32_t   enter_chdev_cmd_write;
220uint32_t   exit_chdev_cmd_write;
221
222uint32_t   enter_chdev_server_write;
223uint32_t   exit_chdev_server_write;
224
225uint32_t   enter_tty_cmd_write;
226uint32_t   exit_tty_cmd_write;
227
228uint32_t   enter_tty_isr_write;
229uint32_t   exit_tty_isr_write;
230#endif
231
[564]232// intrumentation variables : cumulated costs per syscall type in cluster
[624]233
234#if CONFIG_INSTRUMENTATION_SYSCALLS
235__attribute__((section(".kdata")))
[564]236uint32_t   syscalls_cumul_cost[SYSCALLS_NR];
237
[624]238__attribute__((section(".kdata")))
[564]239uint32_t   syscalls_occurences[SYSCALLS_NR];
[624]240#endif
[564]241
[1]242///////////////////////////////////////////////////////////////////////////////////////////
[5]243// This function displays the ALMOS_MKH banner.
[1]244///////////////////////////////////////////////////////////////////////////////////////////
[5]245static void print_banner( uint32_t nclusters , uint32_t ncores )
[127]246{
[5]247    printk("\n"
248           "                    _        __    __     _____     ______         __    __    _   __   _     _   \n"
249           "          /\\       | |      |  \\  /  |   / ___ \\   / _____|       |  \\  /  |  | | / /  | |   | |  \n"
250           "         /  \\      | |      |   \\/   |  | /   \\ | | /             |   \\/   |  | |/ /   | |   | |  \n"
251           "        / /\\ \\     | |      | |\\  /| |  | |   | | | |_____   ___  | |\\  /| |  |   /    | |___| |  \n"
252           "       / /__\\ \\    | |      | | \\/ | |  | |   | | \\_____  \\ |___| | | \\/ | |  |   \\    |  ___  |  \n"
253           "      / ______ \\   | |      | |    | |  | |   | |       | |       | |    | |  | |\\ \\   | |   | |  \n"
254           "     / /      \\ \\  | |____  | |    | |  | \\___/ |  _____/ |       | |    | |  | | \\ \\  | |   | |  \n"
255           "    /_/        \\_\\ |______| |_|    |_|   \\_____/  |______/        |_|    |_|  |_|  \\_\\ |_|   |_|  \n"
256           "\n\n\t\t Advanced Locality Management Operating System / Multi Kernel Hybrid\n"
[457]257           "\n\n\t\t %s / %d cluster(s) / %d core(s) per cluster\n\n",
[635]258           CONFIG_VERSION , nclusters , ncores );
[5]259}
[1]260
261
[5]262///////////////////////////////////////////////////////////////////////////////////////////
[564]263// This function initializes the TXT_TX[0] and TXT_RX[0] chdev descriptors, implementing
264// the "kernel terminal", shared by all kernel instances for debug messages.
265// These chdev are implemented as global variables (replicated in all clusters),
266// because this terminal is used before the kmem allocator initialisation, but only
267// the chdevs in cluster 0 are registered in the "chdev_dir" directory.
[127]268// As this TXT0 chdev supports only the TXT_SYNC_WRITE command, we don't create
269// a server thread, we don't allocate a WTI, and we don't initialize the waiting queue.
[564]270// Note: The TXT_RX[0] chdev is created, but is not used by ALMOS-MKH (september 2018).
[5]271///////////////////////////////////////////////////////////////////////////////////////////
272// @ info    : pointer on the local boot-info structure.
273///////////////////////////////////////////////////////////////////////////////////////////
[564]274static void __attribute__ ((noinline)) txt0_device_init( boot_info_t * info )
[5]275{
276    boot_device_t * dev_tbl;         // pointer on array of devices in boot_info
[127]277    uint32_t        dev_nr;          // actual number of devices in this cluster
278    xptr_t          base;            // remote pointer on segment base
279    uint32_t        func;            // device functional index
[5]280    uint32_t        impl;            // device implementation index
[127]281    uint32_t        i;               // device index in dev_tbl
282    uint32_t        x;               // X cluster coordinate
283    uint32_t        y;               // Y cluster coordinate
[1]284
[5]285    // get number of peripherals and base of devices array from boot_info
[127]286    dev_nr      = info->ext_dev_nr;
[5]287    dev_tbl     = info->ext_dev;
[1]288
[14]289    // loop on external peripherals to find TXT device
[127]290    for( i = 0 ; i < dev_nr ; i++ )
291    {
[5]292        base        = dev_tbl[i].base;
[188]293        func        = FUNC_FROM_TYPE( dev_tbl[i].type );
294        impl        = IMPL_FROM_TYPE( dev_tbl[i].type );
[5]295
[127]296        if (func == DEV_FUNC_TXT )
[5]297        {
[564]298            // initialize TXT_TX[0] chdev
299            txt0_tx_chdev.func    = func;
300            txt0_tx_chdev.impl    = impl;
301            txt0_tx_chdev.channel = 0;
302            txt0_tx_chdev.base    = base;
303            txt0_tx_chdev.is_rx   = false;
304            remote_busylock_init( XPTR( local_cxy , &txt0_tx_chdev.wait_lock ),
305                                  LOCK_CHDEV_TXT0 );
[188]306           
[669]307            // make TXT specific initialisations
308            dev_txt_init( &txt0_tx_chdev );                 
309
[564]310            // initialize TXT_RX[0] chdev
311            txt0_rx_chdev.func    = func;
312            txt0_rx_chdev.impl    = impl;
313            txt0_rx_chdev.channel = 0;
314            txt0_rx_chdev.base    = base;
315            txt0_rx_chdev.is_rx   = true;
316            remote_busylock_init( XPTR( local_cxy , &txt0_rx_chdev.wait_lock ),
317                                  LOCK_CHDEV_TXT0 );
318           
319            // make TXT specific initialisations
320            dev_txt_init( &txt0_rx_chdev );
[14]321
[564]322            // register TXT_TX[0] & TXT_RX[0] in chdev_dir[x][y]
323            // for all valid clusters             
[5]324            for( x = 0 ; x < info->x_size ; x++ )
325            {
[564]326                for( y = 0 ; y < info->y_size ; y++ )
[5]327                {
[564]328                    cxy_t cxy = HAL_CXY_FROM_XY( x , y );
329
330                    if( cluster_is_active( cxy ) )
331                    {
332                        hal_remote_s64( XPTR( cxy , &chdev_dir.txt_tx[0] ) ,
333                                        XPTR( local_cxy , &txt0_tx_chdev ) );
334                        hal_remote_s64( XPTR( cxy , &chdev_dir.txt_rx[0] ) ,
335                                        XPTR( local_cxy , &txt0_rx_chdev ) );
[559]336                    }
[5]337                }
338            }
[564]339
340            hal_fence();
[5]341        }
[188]342        } // end loop on devices
343}  // end txt0_device_init()
[5]344
[1]345///////////////////////////////////////////////////////////////////////////////////////////
[188]346// This function allocates memory and initializes the chdev descriptors for the internal
347// peripherals contained in the local cluster, other than the LAPIC, as specified by
348// the boot_info, including the linking with the driver for the specified implementation.
349// The relevant entries in all copies of the devices directory are initialised.
[1]350///////////////////////////////////////////////////////////////////////////////////////////
351// @ info    : pointer on the local boot-info structure.
352///////////////////////////////////////////////////////////////////////////////////////////
[564]353static void __attribute__ ((noinline)) internal_devices_init( boot_info_t * info )
[1]354{
[188]355    boot_device_t * dev_tbl;         // pointer on array of internaldevices in boot_info
356        uint32_t        dev_nr;          // actual number of devices in this cluster
357        xptr_t          base;            // remote pointer on segment base
358    uint32_t        func;            // device functionnal index
359    uint32_t        impl;            // device implementation index
360        uint32_t        i;               // device index in dev_tbl
361        uint32_t        x;               // X cluster coordinate
362        uint32_t        y;               // Y cluster coordinate
363        uint32_t        channels;        // number of channels
364        uint32_t        channel;         // channel index
365        chdev_t       * chdev_ptr;       // local pointer on created chdev
[1]366
[188]367    // get number of internal peripherals and base from boot_info
368        dev_nr  = info->int_dev_nr;
369    dev_tbl = info->int_dev;
[1]370
[188]371    // loop on internal peripherals
372        for( i = 0 ; i < dev_nr ; i++ )
373        {
374        base        = dev_tbl[i].base;
375        channels    = dev_tbl[i].channels;
376        func        = FUNC_FROM_TYPE( dev_tbl[i].type );
377        impl        = IMPL_FROM_TYPE( dev_tbl[i].type );
[204]378 
[188]379        //////////////////////////
380        if( func == DEV_FUNC_MMC ) 
[5]381        {
[188]382            // create chdev in local cluster
383            chdev_ptr = chdev_create( func,
384                                      impl,
385                                      0,          // channel
386                                      false,      // direction
387                                      base );
[564]388            if( chdev_ptr == NULL )
[580]389            {
390                printk("\n[PANIC] in %s : cannot create MMC chdev\n",
391                __FUNCTION__ );
392                hal_core_sleep();
393            }
[188]394           
[683]395#if (DEBUG_KERNEL_INIT & 0x1)
396if( hal_time_stamp() > DEBUG_KERNEL_INIT )
397printk("\n[%s] created chdev[%x,%x] for MMC\n",
398__FUNCTION__ , local_cxy , chdev_ptr );
399#endif
[188]400            // make MMC specific initialisation
401            dev_mmc_init( chdev_ptr );
[1]402
[188]403            // set the MMC field in all chdev_dir[x][y] structures
404            for( x = 0 ; x < info->x_size ; x++ )
[1]405            {
[564]406                for( y = 0 ; y < info->y_size ; y++ )
[188]407                {
[564]408                    cxy_t cxy = HAL_CXY_FROM_XY( x , y );
409
410                    if( cluster_is_active( cxy ) )
411                    {
412                        hal_remote_s64( XPTR( cxy , &chdev_dir.mmc[local_cxy] ), 
[559]413                                        XPTR( local_cxy , chdev_ptr ) );
414                    }
[188]415                }
[1]416            }
[188]417
[438]418#if( DEBUG_KERNEL_INIT & 0x1 )
419if( hal_time_stamp() > DEBUG_KERNEL_INIT )
[683]420printk("\n[%s] initialised chdev[%x,%x] for MMC\n",
[407]421__FUNCTION__ , local_cxy , chdev_ptr );
[389]422#endif
[14]423        }
[188]424        ///////////////////////////////
425        else if( func == DEV_FUNC_DMA )
[127]426        {
[188]427            // create one chdev per channel in local cluster
428            for( channel = 0 ; channel < channels ; channel++ )
429            {   
430                // create chdev[channel] in local cluster
431                chdev_ptr = chdev_create( func,
432                                          impl,
433                                          channel,
434                                          false,     // direction
435                                          base );
[564]436                if( chdev_ptr == NULL )
[580]437                {
438                    printk("\n[PANIC] in %s : cannot create DMA chdev\n",
439                    __FUNCTION__ );
440                    hal_core_sleep();
441                }
[564]442           
[683]443#if (DEBUG_KERNEL_INIT & 0x1)
444if( hal_time_stamp() > DEBUG_KERNEL_INIT )
445printk("\n[%s] cxy %x : created chdev[%x,%x] for DMA[%d]\n",
446__FUNCTION__ , local_cxy , chdev_ptr , channel );
447#endif
[188]448                // make DMA specific initialisation
449                dev_dma_init( chdev_ptr );     
[127]450
[188]451                // initialize only the DMA[channel] field in the local chdev_dir[x][y]
452                // structure because the DMA device is not remotely accessible.
453                chdev_dir.dma[channel] = XPTR( local_cxy , chdev_ptr );
[5]454
[438]455#if( DEBUG_KERNEL_INIT & 0x1 )
456if( hal_time_stamp() > DEBUG_KERNEL_INIT )
[683]457printk("\n[%s] initialised chdev[%x,%x] for DMA[%d]\n",
458__FUNCTION__ , local_cxy , chdev_ptr , channel );
[389]459#endif
[188]460            }
[14]461        }
[127]462    }
[5]463}  // end internal_devices_init()
464
465///////////////////////////////////////////////////////////////////////////////////////////
[188]466// This function allocates memory and initializes the chdev descriptors for the 
[408]467// external (shared) peripherals other than the IOPIC, as specified by the boot_info.
468// This includes the dynamic linking with the driver for the specified implementation.
[188]469// These chdev descriptors are distributed on all clusters, using a modulo on a global
[408]470// index, identically computed in all clusters.
[683]471// This function is executed in all clusters by the core[0], that computes a global index
472// for all external chdevs. Each core[0] core creates only the chdevs that must be placed 
473// in the local cluster, because the global index matches the local index.
[188]474// The relevant entries in all copies of the devices directory are initialised.
[5]475///////////////////////////////////////////////////////////////////////////////////////////
476// @ info    : pointer on the local boot-info structure.
477///////////////////////////////////////////////////////////////////////////////////////////
478static void external_devices_init( boot_info_t * info )
479{
[188]480    boot_device_t * dev_tbl;         // pointer on array of external devices in boot_info
481        uint32_t        dev_nr;          // actual number of external devices
482        xptr_t          base;            // remote pointer on segment base
[5]483    uint32_t        func;            // device functionnal index
484    uint32_t        impl;            // device implementation index
[188]485        uint32_t        i;               // device index in dev_tbl
486        uint32_t        x;               // X cluster coordinate
487        uint32_t        y;               // Y cluster coordinate
488        uint32_t        channels;        // number of channels
489        uint32_t        channel;         // channel index
490        uint32_t        directions;      // number of directions (1 or 2)
491        uint32_t        rx;              // direction index (0 or 1)
[127]492    chdev_t       * chdev;           // local pointer on one channel_device descriptor
[188]493    uint32_t        ext_chdev_gid;   // global index of external chdev
[5]494
495    // get number of peripherals and base of devices array from boot_info
[127]496    dev_nr      = info->ext_dev_nr;
[5]497    dev_tbl     = info->ext_dev;
498
[683]499    // initializes global index (PIC is already placed in cluster 0)
[188]500    ext_chdev_gid = 1;
501
[5]502    // loop on external peripherals
[127]503    for( i = 0 ; i < dev_nr ; i++ )
504    {
[188]505        base     = dev_tbl[i].base;
506        channels = dev_tbl[i].channels;
507        func     = FUNC_FROM_TYPE( dev_tbl[i].type );
508        impl     = IMPL_FROM_TYPE( dev_tbl[i].type );
[5]509
[407]510        // There is one chdev per direction for NIC and for TXT
511        if((func == DEV_FUNC_NIC) || (func == DEV_FUNC_TXT)) directions = 2;
512        else                                                 directions = 1;
[5]513
[407]514        // do nothing for ROM, that does not require a device descriptor.
[5]515        if( func == DEV_FUNC_ROM ) continue;
516
[188]517        // do nothing for PIC, that is already initialized
518        if( func == DEV_FUNC_PIC ) continue;
[5]519
[188]520        // check PIC device initialized
[564]521        if( chdev_dir.pic == XPTR_NULL )
[580]522        {
523            printk("\n[PANIC] in %s : PIC device must be initialized first\n",
524            __FUNCTION__ );
525            hal_core_sleep();
526        }
[188]527
528        // check external device functionnal type
[683]529        if( (func != DEV_FUNC_IOB) && 
530            (func != DEV_FUNC_IOC) && 
531            (func != DEV_FUNC_TXT) &&
532            (func != DEV_FUNC_NIC) && 
533            (func != DEV_FUNC_FBF) )
[580]534        {
535            printk("\n[PANIC] in %s : undefined peripheral type\n",
536            __FUNCTION__ );
537            hal_core_sleep();
538        }
[188]539
[683]540        // loop on channels
[428]541        for( channel = 0 ; channel < channels ; channel++ )
[127]542        {
[5]543            // loop on directions
[188]544            for( rx = 0 ; rx < directions ; rx++ )
[1]545            {
[564]546                // skip TXT0 that has already been initialized
547                if( (func == DEV_FUNC_TXT) && (channel == 0) ) continue;
[428]548
[564]549                // all kernel instances compute the target cluster for all chdevs,
[683]550                // and the global index ext_chdev_gid[func,channel,direction]
[564]551                cxy_t target_cxy;
552                while( 1 )
[536]553                {
[564]554                    uint32_t offset     = ext_chdev_gid % ( info->x_size * info->y_size );
555                    uint32_t x          = offset / info->y_size;
556                    uint32_t y          = offset % info->y_size;
[536]557
[564]558                    target_cxy = HAL_CXY_FROM_XY( x , y );
559
560                    // exit loop if target cluster is active
561                    if( cluster_is_active( target_cxy ) ) break;
562               
563                    // increment global index otherwise
564                    ext_chdev_gid++;
[550]565                }
566
[5]567                // allocate and initialize a local chdev
[407]568                // when local cluster matches target cluster
[5]569                if( target_cxy == local_cxy )
[1]570                {
[5]571                    chdev = chdev_create( func,
572                                          impl,
573                                          channel,
[188]574                                          rx,          // direction
[5]575                                          base );
576
[564]577                    if( chdev == NULL )
[580]578                    {
579                        printk("\n[PANIC] in %s : cannot allocate chdev\n",
580                        __FUNCTION__ );
581                        hal_core_sleep();
582                    }
[5]583
[683]584#if (DEBUG_KERNEL_INIT & 0x1)
585if( hal_time_stamp() > DEBUG_KERNEL_INIT )
586printk("\n[%s] created chdev[%x,%x] for %s[%d] / is_rx %d\n",
587__FUNCTION__ , local_cxy , chdev , chdev_func_str(func) , channel , rx );
588#endif
[5]589                    // make device type specific initialisation
590                    if     ( func == DEV_FUNC_IOB ) dev_iob_init( chdev );
591                    else if( func == DEV_FUNC_IOC ) dev_ioc_init( chdev );
592                    else if( func == DEV_FUNC_TXT ) dev_txt_init( chdev );
593                    else if( func == DEV_FUNC_NIC ) dev_nic_init( chdev );
[188]594                    else if( func == DEV_FUNC_FBF ) dev_fbf_init( chdev );
[5]595
[127]596                    // all external (shared) devices are remotely accessible
[5]597                    // initialize the replicated chdev_dir[x][y] structures
[127]598                    // defining the extended pointers on chdev descriptors
[633]599                    xptr_t * entry = NULL;
[127]600
[188]601                    if(func==DEV_FUNC_IOB             ) entry  = &chdev_dir.iob;
602                    if(func==DEV_FUNC_IOC             ) entry  = &chdev_dir.ioc[channel];
603                    if(func==DEV_FUNC_FBF             ) entry  = &chdev_dir.fbf[channel];
[407]604                    if((func==DEV_FUNC_TXT) && (rx==0)) entry  = &chdev_dir.txt_tx[channel];
605                    if((func==DEV_FUNC_TXT) && (rx==1)) entry  = &chdev_dir.txt_rx[channel];
[188]606                    if((func==DEV_FUNC_NIC) && (rx==0)) entry  = &chdev_dir.nic_tx[channel];
607                    if((func==DEV_FUNC_NIC) && (rx==1)) entry  = &chdev_dir.nic_rx[channel];
[127]608
[1]609                    for( x = 0 ; x < info->x_size ; x++ )
610                    {
[564]611                        for( y = 0 ; y < info->y_size ; y++ )
[1]612                        {
[564]613                            cxy_t cxy = HAL_CXY_FROM_XY( x , y );
614
[633]615                            if( cluster_is_active( cxy ) && ( entry != NULL ) )
[564]616                            {
617                                hal_remote_s64( XPTR( cxy , entry ),
[559]618                                                XPTR( local_cxy , chdev ) );
619                            }
[5]620                        }
[1]621                    }
622
[683]623#if( DEBUG_KERNEL_INIT & 1 )
[438]624if( hal_time_stamp() > DEBUG_KERNEL_INIT )
[683]625printk("\n[%s] initialised chdev[%x,%x] for %s\n",
626__FUNCTION__ , local_cxy, chdev , chdev->name );
[389]627#endif
[683]628
[5]629                }  // end if match
630
[19]631                // increment chdev global index (matching or not)
[188]632                ext_chdev_gid++;
[5]633
634            } // end loop on directions
635        }  // end loop on channels
[188]636        } // end loop on devices
637}  // end external_devices_init()
[5]638
[188]639///////////////////////////////////////////////////////////////////////////////////////////
[683]640// This function is called by core[0][0] to allocate memory and initialize the PIC
[407]641// device, namely the informations attached to the external IOPIC controller, that
642// must be replicated in all clusters (struct iopic_input).
[188]643// This initialisation must be done before other devices initialisation because the IRQ
[407]644// routing infrastructure is required for both internal and external devices init.
[188]645///////////////////////////////////////////////////////////////////////////////////////////
646// @ info    : pointer on the local boot-info structure.
647///////////////////////////////////////////////////////////////////////////////////////////
[564]648static void __attribute__ ((noinline)) iopic_init( boot_info_t * info )
[188]649{
650    boot_device_t * dev_tbl;         // pointer on boot_info external devices array
651        uint32_t        dev_nr;          // actual number of external devices
652        xptr_t          base;            // remote pointer on segment base
653    uint32_t        func;            // device functionnal index
654    uint32_t        impl;            // device implementation index
655        uint32_t        i;               // device index in dev_tbl
656    uint32_t        x;               // cluster X coordinate
657    uint32_t        y;               // cluster Y coordinate
658    bool_t          found;           // IOPIC found
659        chdev_t       * chdev;           // pointer on PIC chdev descriptor
660
661    // get number of external peripherals and base of array from boot_info
662        dev_nr      = info->ext_dev_nr;
663    dev_tbl     = info->ext_dev;
664
[564]665    // avoid GCC warning
666    base        = XPTR_NULL;
667    impl        = 0;
668
[188]669    // loop on external peripherals to get the IOPIC 
670        for( i = 0 , found = false ; i < dev_nr ; i++ )
671        {
672        func = FUNC_FROM_TYPE( dev_tbl[i].type );
673
[127]674        if( func == DEV_FUNC_PIC )
[1]675        {
[188]676            base     = dev_tbl[i].base;
677            impl     = IMPL_FROM_TYPE( dev_tbl[i].type );
678            found    = true;
679            break;
680        }
681    }
[5]682
[564]683    // check PIC existence
684    if( found == false )
[580]685    {
686        printk("\n[PANIC] in %s : PIC device not found\n",
687        __FUNCTION__ );
688        hal_core_sleep();
689    }
[1]690
[407]691    // allocate and initialize the PIC chdev in cluster 0
692    chdev = chdev_create( DEV_FUNC_PIC,
[188]693                          impl,
694                          0,      // channel
695                          0,      // direction,
696                          base );
[5]697
[564]698    // check memory
699    if( chdev == NULL )
[580]700    {
701        printk("\n[PANIC] in %s : no memory for PIC chdev\n",
702        __FUNCTION__ );
703        hal_core_sleep();
704    }
[5]705
[188]706    // make PIC device type specific initialisation
707    dev_pic_init( chdev );
[1]708
[407]709    // register, in all clusters, the extended pointer
710    // on PIC chdev in "chdev_dir" array
[188]711    xptr_t * entry = &chdev_dir.pic;   
712               
713    for( x = 0 ; x < info->x_size ; x++ )
714    {
[564]715        for( y = 0 ; y < info->y_size ; y++ )
[188]716        {
[564]717            cxy_t cxy = HAL_CXY_FROM_XY( x , y );
718
719            if( cluster_is_active( cxy ) )
720            {
721                hal_remote_s64( XPTR( cxy , entry ) , 
[559]722                                XPTR( local_cxy , chdev ) );
723            }
[188]724        }
725    }
[1]726
[407]727    // initialize, in all clusters, the "iopic_input" structure
[188]728    // defining how external IRQs are connected to IOPIC
729
[407]730    // register default value for unused inputs
731    for( x = 0 ; x < info->x_size ; x++ )
732    {
[564]733        for( y = 0 ; y < info->y_size ; y++ )
[407]734        {
[564]735            cxy_t cxy = HAL_CXY_FROM_XY( x , y );
736
737            if( cluster_is_active( cxy ) )
738            {
739                hal_remote_memset( XPTR( cxy , &iopic_input ), 
740                                   0xFF , sizeof(iopic_input_t) );
[559]741            }
[407]742        }
743    }
744
745    // register input IRQ index for valid inputs
[577]746    uint32_t   id;             // input IRQ index
747    uint8_t    valid;          // input IRQ is connected
748    uint32_t   type;           // source device type
749    uint8_t    channel;        // source device channel
750    uint8_t    is_rx;          // source device direction
751    uint32_t * ptr = NULL;     // local pointer on one field in iopic_input stucture
[407]752
[188]753    for( id = 0 ; id < CONFIG_MAX_EXTERNAL_IRQS ; id++ )
754    {
755        valid   = dev_tbl[i].irq[id].valid;
756        type    = dev_tbl[i].irq[id].dev_type;
757        channel = dev_tbl[i].irq[id].channel;
758        is_rx   = dev_tbl[i].irq[id].is_rx;
[407]759        func    = FUNC_FROM_TYPE( type );
[188]760
[407]761        // get pointer on relevant field in iopic_input
762        if( valid )
[188]763        {
[407]764            if     ( func == DEV_FUNC_IOC )                 ptr = &iopic_input.ioc[channel]; 
765            else if((func == DEV_FUNC_TXT) && (is_rx == 0)) ptr = &iopic_input.txt_tx[channel];
766            else if((func == DEV_FUNC_TXT) && (is_rx != 0)) ptr = &iopic_input.txt_rx[channel];
[492]767            else if((func == DEV_FUNC_NIC) && (is_rx == 0)) ptr = &iopic_input.nic_tx[channel];
768            else if((func == DEV_FUNC_NIC) && (is_rx != 0)) ptr = &iopic_input.nic_rx[channel];
769            else if( func == DEV_FUNC_IOB )                 ptr = &iopic_input.iob;
[580]770            else
771            {
772                printk("\n[PANIC] in %s : illegal source device for IOPIC input\n",
773                __FUNCTION__ );
774                hal_core_sleep();
775            }
[188]776
[407]777            // set one entry in all "iopic_input" structures
778            for( x = 0 ; x < info->x_size ; x++ )
779            {
[564]780                for( y = 0 ; y < info->y_size ; y++ )
[407]781                {
[564]782                    cxy_t cxy = HAL_CXY_FROM_XY( x , y );
783
784                    if( cluster_is_active( cxy ) )
785                    {
786                        hal_remote_s64( XPTR( cxy , ptr ) , id ); 
[559]787                    }
[407]788                }
789            }
[188]790        }
791    } 
792
[438]793#if( DEBUG_KERNEL_INIT & 0x1 )
[601]794if( hal_time_stamp() > DEBUG_KERNEL_INIT )
[407]795{
[601]796    printk("\n[%s] created PIC chdev in cluster %x at cycle %d\n",
[407]797    __FUNCTION__ , local_cxy , (uint32_t)hal_time_stamp() );
798    dev_pic_inputs_display();
799}
[389]800#endif
[188]801   
802}  // end iopic_init()
803
[1]804///////////////////////////////////////////////////////////////////////////////////////////
[623]805// This function is called by all core[0]s in all cluster to complete the PIC device
[188]806// initialisation, namely the informations attached to the LAPIC controller.
807// This initialisation must be done after the IOPIC initialisation, but before other
808// devices initialisation because the IRQ routing infrastructure is required for both
809// internal and external devices initialisation.
810///////////////////////////////////////////////////////////////////////////////////////////
811// @ info    : pointer on the local boot-info structure.
812///////////////////////////////////////////////////////////////////////////////////////////
[564]813static void __attribute__ ((noinline)) lapic_init( boot_info_t * info )
[188]814{
815    boot_device_t * dev_tbl;      // pointer on boot_info internal devices array
816    uint32_t        dev_nr;       // number of internal devices
817    uint32_t        i;            // device index in dev_tbl
818        xptr_t          base;         // remote pointer on segment base
819    uint32_t        func;         // device functionnal type in boot_info
820    bool_t          found;        // LAPIC found
821
822    // get number of internal peripherals and base
823        dev_nr      = info->int_dev_nr;
824    dev_tbl     = info->int_dev;
825
826    // loop on internal peripherals to get the lapic device
827        for( i = 0 , found = false ; i < dev_nr ; i++ )
828        {
829        func = FUNC_FROM_TYPE( dev_tbl[i].type );
830
831        if( func == DEV_FUNC_ICU )
832        {
833            base     = dev_tbl[i].base;
834            found    = true;
835            break;
836        }
837    }
838
839    // if the LAPIC controller is not defined in the boot_info,
840    // we simply don't initialize the PIC extensions in the kernel,
841    // making the assumption that the LAPIC related informations
842    // are hidden in the hardware specific PIC driver.
843    if( found )
844    {
845        // initialise the PIC extensions for
846        // the core descriptor and core manager extensions
847        dev_pic_extend_init( (uint32_t *)GET_PTR( base ) );
848
849        // initialize the "lapic_input" structure
850        // defining how internal IRQs are connected to LAPIC
851        uint32_t        id;
852        uint8_t         valid;
853        uint8_t         channel;
854        uint32_t        func;
855
856        for( id = 0 ; id < CONFIG_MAX_INTERNAL_IRQS ; id++ )
857        {
858            valid    = dev_tbl[i].irq[id].valid;
859            func     = FUNC_FROM_TYPE( dev_tbl[i].irq[id].dev_type );
860            channel  = dev_tbl[i].irq[id].channel;
861
862            if( valid ) // only valid local IRQs are registered
863            {
864                if     ( func == DEV_FUNC_MMC ) lapic_input.mmc = id;
865                else if( func == DEV_FUNC_DMA ) lapic_input.dma[channel] = id;
[580]866                else
867                {
868                    printk("\n[PANIC] in %s : illegal source device for LAPIC input\n",
869                    __FUNCTION__ );
870                    hal_core_sleep();
871                }
[188]872            }
873        }
874    }
875}  // end lapic_init()
876
877///////////////////////////////////////////////////////////////////////////////////////////
[14]878// This static function returns the identifiers of the calling core.
879///////////////////////////////////////////////////////////////////////////////////////////
880// @ info    : pointer on boot_info structure.
881// @ lid     : [out] core local index in cluster.
882// @ cxy     : [out] cluster identifier.
883// @ lid     : [out] core global identifier (hardware).
[657]884// @ return 0 if success / return -1 if not found.
[14]885///////////////////////////////////////////////////////////////////////////////////////////
[564]886static error_t __attribute__ ((noinline)) get_core_identifiers( boot_info_t * info,
887                                                                lid_t       * lid,
888                                                                cxy_t       * cxy,
889                                                                gid_t       * gid )
[14]890{
[127]891    uint32_t   i;
[14]892    gid_t      global_id;
[19]893
[14]894    // get global identifier from hardware register
[127]895    global_id = hal_get_gid();
[14]896
897    // makes an associative search in boot_info to get (cxy,lid) from global_id
898    for( i = 0 ; i < info->cores_nr ; i++ )
899    {
900        if( global_id == info->core[i].gid )
901        {
902            *lid = info->core[i].lid;
903            *cxy = info->core[i].cxy;
904            *gid = global_id;
905            return 0;
906        }
907    }
[657]908    return -1;
[19]909}
[14]910
[626]911
912
913
914
[14]915///////////////////////////////////////////////////////////////////////////////////////////
[1]916// This function is the entry point for the kernel initialisation.
[651]917// It is executed by all cores in all clusters, but only core[cxy][0] initializes
[623]918// the shared resources such as the cluster manager, or the local peripherals.
[19]919// To comply with the multi-kernels paradigm, it accesses only local cluster memory, using
920// only information contained in the local boot_info_t structure, set by the bootloader.
[623]921// Only core[0] in cluster 0 print the log messages.
[1]922///////////////////////////////////////////////////////////////////////////////////////////
923// @ info    : pointer on the local boot-info structure.
924///////////////////////////////////////////////////////////////////////////////////////////
925void kernel_init( boot_info_t * info )
926{
[204]927    lid_t        core_lid = -1;             // running core local index
928    cxy_t        core_cxy = -1;             // running core cluster identifier
929    gid_t        core_gid;                  // running core hardware identifier
930    cluster_t  * cluster;                   // pointer on local cluster manager
931    core_t     * core;                      // pointer on running core descriptor
932    thread_t   * thread;                    // pointer on idle thread descriptor
933
934    xptr_t       vfs_root_inode_xp;         // extended pointer on VFS root inode
935    xptr_t       devfs_dev_inode_xp;        // extended pointer on DEVFS dev inode   
936    xptr_t       devfs_external_inode_xp;   // extended pointer on DEVFS external inode       
937
[1]938    error_t      error;
[285]939    reg_t        status;                    // running core status register
[1]940
[188]941    /////////////////////////////////////////////////////////////////////////////////
[623]942    // STEP 1 : Each core get its core identifier from boot_info, and makes
[188]943    //          a partial initialisation of its private idle thread descriptor.
[623]944    //          core[0] initializes the "local_cxy" global variable.
945    //          core[0] in cluster[0] initializes the TXT0 chdev for log messages.
[188]946    /////////////////////////////////////////////////////////////////////////////////
947
[23]948    error = get_core_identifiers( info,
[14]949                                  &core_lid,
950                                  &core_cxy,
951                                  &core_gid );
[1]952
[623]953    // core[0] initialize cluster identifier
[14]954    if( core_lid == 0 ) local_cxy = info->cxy;
[1]955
[127]956    // each core gets a pointer on its private idle thread descriptor
957    thread = (thread_t *)( idle_threads + (core_lid * CONFIG_THREAD_DESC_SIZE) );
[68]958
[127]959    // each core registers this thread pointer in hardware register
[68]960    hal_set_current_thread( thread );
[71]961
[407]962    // each core register core descriptor pointer in idle thread descriptor
963    thread->core = &LOCAL_CLUSTER->core_tbl[core_lid];
964
[564]965    // each core initializes the idle thread locks counters
966    thread->busylocks = 0;
[124]967
[564]968#if DEBUG_BUSYLOCK
969    // each core initialise the idle thread list of busylocks
970    xlist_root_init( XPTR( local_cxy , &thread->busylocks_root ) );
971#endif
[14]972
[623]973    // core[0] initializes cluster info
[564]974    if( core_lid == 0 ) cluster_info_init( info );
975
[623]976    // core[0] in cluster[0] initialises TXT0 chdev descriptor
[564]977    if( (core_lid == 0) && (core_cxy == 0) ) txt0_device_init( info );
978
[623]979    // all cores check identifiers
980    if( error )
981    {
982        printk("\n[PANIC] in %s : illegal core : gid %x / cxy %x / lid %d",
983        __FUNCTION__, core_lid, core_cxy, core_lid );
984        hal_core_sleep();
985    }
986
[14]987    /////////////////////////////////////////////////////////////////////////////////
[564]988    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
989                                        (info->x_size * info->y_size) );
[14]990    barrier_wait( &local_barrier , info->cores_nr );
[437]991    /////////////////////////////////////////////////////////////////////////////////
[14]992
[438]993#if DEBUG_KERNEL_INIT
[583]994if( (core_lid ==  0) & (local_cxy == 0) ) 
[624]995printk("\n[%s] exit barrier 1 : TXT0 initialized / cycle %d\n",
[610]996__FUNCTION__, (uint32_t)hal_get_cycles() );
[437]997#endif
[14]998
[623]999    /////////////////////////////////////////////////////////////////////////////////
[637]1000    // STEP 2 : core[0] initializes the cluster manager,
1001    //          including the physical memory allocators.
[623]1002    /////////////////////////////////////////////////////////////////////////////////
[188]1003
[651]1004    // core[0] initialises DQDT (only core[0][0] build the quad-tree)
[582]1005    if( core_lid == 0 ) dqdt_init();
1006   
[623]1007    // core[0] initialize other cluster manager complex structures
[14]1008    if( core_lid == 0 )
[1]1009    {
[564]1010        error = cluster_manager_init( info );
[1]1011
[14]1012        if( error )
[580]1013        {
1014             printk("\n[PANIC] in %s : cannot initialize cluster manager in cluster %x\n",
1015             __FUNCTION__, local_cxy );
1016             hal_core_sleep();
1017        }
[14]1018    }
[5]1019
[14]1020    /////////////////////////////////////////////////////////////////////////////////
[564]1021    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
1022                                        (info->x_size * info->y_size) );
[14]1023    barrier_wait( &local_barrier , info->cores_nr );
1024    /////////////////////////////////////////////////////////////////////////////////
[1]1025
[438]1026#if DEBUG_KERNEL_INIT
1027if( (core_lid ==  0) & (local_cxy == 0) ) 
[624]1028printk("\n[%s] exit barrier 2 : cluster manager initialized / cycle %d\n",
[610]1029__FUNCTION__, (uint32_t)hal_get_cycles() );
[437]1030#endif
[1]1031
[188]1032    /////////////////////////////////////////////////////////////////////////////////
[624]1033    // STEP 3 : all cores initialize the idle thread descriptor.
1034    //          core[0] initializes the process_zero descriptor,
[623]1035    //          including the kernel VMM (both GPT and VSL)
[188]1036    /////////////////////////////////////////////////////////////////////////////////
1037
1038    // all cores get pointer on local cluster manager & core descriptor
[14]1039    cluster = &cluster_manager;
[127]1040    core    = &cluster->core_tbl[core_lid];
[1]1041
[624]1042    // all cores update the register(s) defining the kernel
1043    // entry points for interrupts, exceptions and syscalls,
1044    // this must be done before VFS initialisation, because
1045    // kernel_init() uses RPCs requiring IPIs...
1046    hal_set_kentry();
1047
1048    // all cores initialize the idle thread descriptor
1049    thread_idle_init( thread,
1050                      THREAD_IDLE,
1051                      &thread_idle_func,
1052                      NULL,
1053                      core_lid );
1054
[623]1055    // core[0] initializes the process_zero descriptor,
1056    if( core_lid == 0 ) process_zero_create( &process_zero , info );
[5]1057
[623]1058    /////////////////////////////////////////////////////////////////////////////////
1059    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
1060                                        (info->x_size * info->y_size) );
1061    barrier_wait( &local_barrier , info->cores_nr );
1062    /////////////////////////////////////////////////////////////////////////////////
1063
1064#if DEBUG_KERNEL_INIT
1065if( (core_lid ==  0) & (local_cxy == 0) ) 
[624]1066printk("\n[%s] exit barrier 3 : kernel processs initialized / cycle %d\n",
[623]1067__FUNCTION__, (uint32_t)hal_get_cycles() );
1068#endif
1069
1070    /////////////////////////////////////////////////////////////////////////////////
1071    // STEP 4 : all cores initialize their private MMU
1072    //          core[0] in cluster 0 initializes the IOPIC device.
1073    /////////////////////////////////////////////////////////////////////////////////
1074
1075    // all cores initialise their MMU
1076    hal_mmu_init( &process_zero.vmm.gpt );
1077
1078    // core[0] in cluster[0] initializes the PIC chdev,
[188]1079    if( (core_lid == 0) && (local_cxy == 0) ) iopic_init( info );
1080   
1081    ////////////////////////////////////////////////////////////////////////////////
[564]1082    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
1083                                        (info->x_size * info->y_size) );
[188]1084    barrier_wait( &local_barrier , info->cores_nr );
1085    ////////////////////////////////////////////////////////////////////////////////
[127]1086
[438]1087#if DEBUG_KERNEL_INIT
1088if( (core_lid ==  0) & (local_cxy == 0) ) 
[624]1089printk("\n[%s] exit barrier 4 : MMU and IOPIC initialized / cycle %d\n",
[610]1090__FUNCTION__, (uint32_t)hal_get_cycles() );
[437]1091#endif
[1]1092
[188]1093    ////////////////////////////////////////////////////////////////////////////////
[637]1094    // STEP 5 : core[0] initialize the distibuted LAPIC descriptor.
1095    //          core[0] initialize the internal chdev descriptors
[623]1096    //          core[0] initialize the local external chdev descriptors
[188]1097    ////////////////////////////////////////////////////////////////////////////////
[5]1098
[623]1099    // all core[0]s initialize their local LAPIC extension,
[279]1100    if( core_lid == 0 ) lapic_init( info );
1101
[623]1102    // core[0] scan the internal (private) peripherals,
[188]1103    // and allocates memory for the corresponding chdev descriptors.
1104    if( core_lid == 0 ) internal_devices_init( info );
[1]1105
[623]1106    // All core[0]s contribute to initialise external peripheral chdev descriptors.
1107    // Each core[0][cxy] scan the set of external (shared) peripherals (but the TXT0),
[14]1108    // and allocates memory for the chdev descriptors that must be placed
[127]1109    // on the (cxy) cluster according to the global index value.
[188]1110
[14]1111    if( core_lid == 0 ) external_devices_init( info );
[1]1112
[14]1113    /////////////////////////////////////////////////////////////////////////////////
[564]1114    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
1115                                        (info->x_size * info->y_size) );
[14]1116    barrier_wait( &local_barrier , info->cores_nr );
1117    /////////////////////////////////////////////////////////////////////////////////
[5]1118
[438]1119#if DEBUG_KERNEL_INIT
1120if( (core_lid ==  0) & (local_cxy == 0) ) 
[624]1121printk("\n[%s] exit barrier 5 : chdevs initialised / cycle %d\n",
[610]1122__FUNCTION__, (uint32_t)hal_get_cycles() );
[437]1123#endif
[1]1124
[657]1125#if CONFIG_INSTRUMENTATION_CHDEVS
[443]1126if( (core_lid ==  0) & (local_cxy == 0) ) 
[437]1127chdev_dir_display();
1128#endif
1129   
[188]1130    /////////////////////////////////////////////////////////////////////////////////
[657]1131    // STEP 6 : All cores enable IPI (Inter Procesor Interrupt),
1132    //          All cores unblock the idle thread, and register it in scheduler.
1133    //          The core[0] in cluster defined by the CONFIG_VFS_ROOT_CXY parameter,
1134    //          access the IOC device to initialize the VFS for the FS identified
1135    //          by the CONFIG_VFS_ROOT_IS_*** parameter. It does the following
1136    //          actions in the VFS_ROOT cluster :
1137    //          1. allocate and initialize the selected FS context,
1138    //          2. create and initializes the VFS root inodes,
1139    //          3. initialize the VFS context for FATFS (in fs_context[] array),
1140    //          4. create the <.> and <..> dentries in VFS root directory,
1141    //          5. register the VFS root inode in process_zero descriptor,
1142    //          6. allocate the DEVFS context,
1143    //          7. initialize the VFS context for DEVFS (in fs_context[] array),
1144    //          8. create the <dev> and <external> inodes,
1145    //          9. initialize the DEVFS context.
[188]1146    /////////////////////////////////////////////////////////////////////////////////
1147
[564]1148    // All cores enable IPI
[279]1149    dev_pic_enable_ipi();
1150    hal_enable_irq( &status );
1151
[624]1152    // all cores unblock the idle thread, and register it in scheduler
[296]1153    thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
[103]1154    core->scheduler.idle = thread;
[1]1155
[657]1156    // core[O] in VFS_ROOT cluster creates the VFS root
1157    if( (core_lid ==  0) && (local_cxy == CONFIG_VFS_ROOT_CXY ) ) 
[14]1158    {
[614]1159        // Only FATFS is supported yet,
[657]1160        // TODO other File System can be introduced below
[23]1161        if( CONFIG_VFS_ROOT_IS_FATFS )
1162        {
[657]1163            // 1. allocate memory and initialize FATFS context in VFS_ROOT cluster
1164            xptr_t  fatfs_ctx_xp = fatfs_ctx_alloc( CONFIG_VFS_ROOT_CXY );
[188]1165
[657]1166            if( fatfs_ctx_xp == XPTR_NULL )
[580]1167            {
[657]1168                printk("\n[PANIC] in %s : cannot allocate FATFS context in cluster %x\n",
1169                __FUNCTION__ , CONFIG_VFS_ROOT_CXY );
[580]1170                hal_core_sleep();
1171            }
[188]1172
[657]1173            // initialise FATFS context in VFS_ROOT cluster from IOC device (boot_record)
1174            error = fatfs_ctx_init( fatfs_ctx_xp );
[626]1175
[657]1176            if( error )
1177            {
1178                printk("\n[PANIC] in %s : cannot initialize FATFS context in cluster %x\n",
1179                __FUNCTION__ , CONFIG_VFS_ROOT_CXY );
1180                hal_core_sleep();
1181            }
1182
1183#if( DEBUG_KERNEL_INIT & 1 )
1184printk("\n[%s] initialized FATFS context in cluster %x\n",
1185__FUNCTION__, CONFIG_VFS_ROOT_CXY );
1186#endif
1187   
1188            // get various informations from FATFS context
1189            fatfs_ctx_t * fatfs_ctx_ptr = GET_PTR( fatfs_ctx_xp );
1190
1191            uint32_t root_dir_cluster    = hal_remote_l32( XPTR( CONFIG_VFS_ROOT_CXY,
1192                                           &fatfs_ctx_ptr->root_dir_cluster ) );
1193
1194            uint32_t bytes_per_sector    = hal_remote_l32( XPTR( CONFIG_VFS_ROOT_CXY,
1195                                           &fatfs_ctx_ptr->bytes_per_sector ) );
[188]1196 
[657]1197            uint32_t sectors_per_cluster = hal_remote_l32( XPTR( CONFIG_VFS_ROOT_CXY,
1198                                           &fatfs_ctx_ptr->sectors_per_cluster ) );
1199 
1200            uint32_t cluster_size        = bytes_per_sector * sectors_per_cluster;
1201 
1202            uint32_t fat_sectors_count   = hal_remote_l32( XPTR( CONFIG_VFS_ROOT_CXY,
1203                                           &fatfs_ctx_ptr->fat_sectors_count ) ) << 7;
1204
1205            uint32_t total_clusters      = fat_sectors_count << 7;
1206 
1207            // 2. create VFS root inode in VFS_ROOT cluster
1208            // TODO define attr, rights, uid, gid
1209            error = vfs_inode_create( CONFIG_VFS_ROOT_CXY,          // target cluster
1210                                      FS_TYPE_FATFS,                // fs_type
1211                                      0,                            // attr
1212                                      0,                            // rights
1213                                      0,                            // uid
1214                                      0,                            // gid
1215                                      &vfs_root_inode_xp );         // return
[564]1216            if( error )
[580]1217            {
[657]1218                printk("\n[PANIC] in %s : cannot create VFS root inode in cluster %x\n",
1219                __FUNCTION__ , CONFIG_VFS_ROOT_CXY );
[580]1220                hal_core_sleep();
1221            }
[188]1222
[657]1223#if( DEBUG_KERNEL_INIT & 1 )
1224vfs_inode_t * root_inode = GET_PTR( vfs_root_inode_xp );
1225printk("\n[%s] created </> root inode %x in cluster %x / ctx %x\n",
1226__FUNCTION__, root_inode, CONFIG_VFS_ROOT_CXY, root_inode->ctx );
1227#endif
1228   
1229            // update FATFS root inode "type" and "extend" fields 
1230            vfs_inode_t * vfs_root_inode_ptr = GET_PTR( vfs_root_inode_xp );
1231
1232            hal_remote_s32( XPTR( CONFIG_VFS_ROOT_CXY , &vfs_root_inode_ptr->type ),
[669]1233                            FILE_TYPE_DIR );
[657]1234
1235            hal_remote_spt( XPTR( CONFIG_VFS_ROOT_CXY , &vfs_root_inode_ptr->extend ), 
[601]1236                            (void*)(intptr_t)root_dir_cluster );
[188]1237
[657]1238            // 3. initialize the VFS context for FATFS in VFS_ROOT cluster
1239            vfs_ctx_init( CONFIG_VFS_ROOT_CXY,                      // target cluster
1240                          FS_TYPE_FATFS,                            // fs type
1241                              total_clusters,                           // number of clusters
1242                              cluster_size,                             // bytes
1243                              vfs_root_inode_xp,                        // VFS root
1244                          fatfs_ctx_ptr );                          // extend
1245
1246#if( DEBUG_KERNEL_INIT & 1 )
1247vfs_ctx_t * vfs_for_fatfs_ctx =  &fs_context[FS_TYPE_FATFS];
1248printk("\n[%s] initialized VFS_for_FATFS context in cluster %x / ctx %x / fs_type %d\n",
1249__FUNCTION__, CONFIG_VFS_ROOT_CXY, vfs_for_fatfs_ctx, vfs_for_fatfs_ctx->type );
1250#endif
[23]1251        }
1252        else
1253        {
[657]1254            printk("\n[PANIC] in %s : unsupported VFS type in cluster %x\n",
1255            __FUNCTION__ , CONFIG_VFS_ROOT_CXY );
[580]1256            hal_core_sleep();
[23]1257        }
1258
[657]1259        // 4. create the <.> and <..> dentries in VFS root directory
[614]1260        // the VFS root parent inode is the VFS root inode itself
1261        vfs_add_special_dentries( vfs_root_inode_xp,
1262                                  vfs_root_inode_xp );
1263
[657]1264        // 5. register VFS root inode in target cluster process_zero descriptor
1265        hal_remote_s64( XPTR( CONFIG_VFS_ROOT_CXY , &process_zero.vfs_root_xp ),
1266                        vfs_root_inode_xp );
1267        hal_remote_s64( XPTR( CONFIG_VFS_ROOT_CXY , &process_zero.cwd_xp ),
1268                        vfs_root_inode_xp );
1269
1270        // 6. allocate memory for DEVFS context in VFS_ROOT cluster
1271        xptr_t devfs_ctx_xp = devfs_ctx_alloc( CONFIG_VFS_ROOT_CXY );
1272
1273        if( devfs_ctx_xp == XPTR_NULL )
1274        {
1275            printk("\n[PANIC] in %s : cannot create DEVFS context in cluster %x\n",
1276            __FUNCTION__ , CONFIG_VFS_ROOT_CXY );
1277            hal_core_sleep();
1278        }
1279
1280        // 7. initialize the VFS context for DEVFS in VFS_ROOT cluster
1281        vfs_ctx_init( CONFIG_VFS_ROOT_CXY,                          // target cluster
1282                      FS_TYPE_DEVFS,                                // fs type
1283                          0,                                            // total_clusters: unused
1284                          0,                                            // cluster_size: unused
1285                          vfs_root_inode_xp,                            // VFS root
1286                      GET_PTR( devfs_ctx_xp ) );                    // extend
1287
1288#if( DEBUG_KERNEL_INIT & 1 )
1289vfs_ctx_t * vfs_for_devfs_ctx =  &fs_context[FS_TYPE_DEVFS];
1290printk("\n[%s] initialized VFS_for_DEVFS context in cluster %x / ctx %x / fs_type %d\n",
1291__FUNCTION__, CONFIG_VFS_ROOT_CXY, vfs_for_devfs_ctx, vfs_for_devfs_ctx->type );
1292#endif
1293
1294        // 8. create "dev" and "external" inodes (directories)
1295        devfs_global_init( vfs_root_inode_xp,
1296                           &devfs_dev_inode_xp,
1297                           &devfs_external_inode_xp );
1298
1299        // 9. initializes DEVFS context in VFS_ROOT cluster
1300        devfs_ctx_init( devfs_ctx_xp,
1301                        devfs_dev_inode_xp,
1302                        devfs_external_inode_xp );
[188]1303    }
1304
1305    /////////////////////////////////////////////////////////////////////////////////
[564]1306    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
1307                                        (info->x_size * info->y_size) );
[188]1308    barrier_wait( &local_barrier , info->cores_nr );
1309    /////////////////////////////////////////////////////////////////////////////////
1310
[438]1311#if DEBUG_KERNEL_INIT
[657]1312if( (core_lid ==  0) & (local_cxy == CONFIG_VFS_ROOT_CXY) ) 
1313printk("\n[%s] exit barrier 6 : VFS root inode (%x) created in cluster (%x) / cycle %d\n",
1314__FUNCTION__, GET_CXY(vfs_root_inode_xp), 
1315GET_PTR(vfs_root_inode_xp), (uint32_t)hal_get_cycles() );
[437]1316#endif
[188]1317
1318    /////////////////////////////////////////////////////////////////////////////////
[657]1319    // STEP 7 : In all clusters other than the VFS_ROOT cluster, the core[0] makes
1320    //          the following local actions to complete the VFS initialisation :
1321    //          1. allocate a local context for the selected FS extension,
1322    //          2. copy FS context from VFS_ROOT cluster to local cluster,
1323    //          3. copy VFS_for_FATFS context from VFS_ROOT cluster to local cluster,
1324    //          4. allocate a local context for the DEVFS extension,
1325    //          5. copy DEVFS context from VFS_ROOT cluster to local cluster,
1326    //          6. update the local "root_inode_xp" field in process_zero.
[188]1327    /////////////////////////////////////////////////////////////////////////////////
1328
[657]1329    if( (core_lid ==  0) && (local_cxy != CONFIG_VFS_ROOT_CXY) ) 
[188]1330    {
[657]1331        // only FATFS is supported yet
1332        // TODO other File System can be introduced below
[188]1333        if( CONFIG_VFS_ROOT_IS_FATFS )
[23]1334        {
[657]1335            // 1. allocate a local FATFS context extension
1336            xptr_t local_fatfs_ctx_xp = fatfs_ctx_alloc( local_cxy );
[188]1337
[657]1338            if( local_fatfs_ctx_xp == XPTR_NULL )
[580]1339            {
1340                printk("\n[PANIC] in %s : cannot create FATFS context in cluster %x\n",
1341                __FUNCTION__ , local_cxy );
1342                hal_core_sleep();
1343            }
[188]1344
[657]1345            // get local pointer on VFS_for_FATFS context (same in all clusters)
1346            vfs_ctx_t * vfs_fat_ctx_ptr = &fs_context[FS_TYPE_FATFS];
[188]1347
[657]1348            // build extended pointer on VFS_for_FATFS "extend" field in VFS_ROOT cluster
1349            xptr_t fatfs_extend_xp = XPTR( CONFIG_VFS_ROOT_CXY , &vfs_fat_ctx_ptr->extend );
[389]1350
[657]1351            // get local pointer on FATFS context in VFS_ROOT cluster
1352            fatfs_ctx_t * remote_fatfs_ctx_ptr = hal_remote_lpt( fatfs_extend_xp );
[389]1353
[657]1354            // build extended pointer on FATFS context in VFS_ROOT cluster
1355            xptr_t remote_fatfs_ctx_xp = XPTR( CONFIG_VFS_ROOT_CXY , remote_fatfs_ctx_ptr );
[188]1356
[657]1357            // 2. copy FATFS context from VFS_ROOT cluster to local cluster
1358            hal_remote_memcpy( local_fatfs_ctx_xp,
1359                               remote_fatfs_ctx_xp,
1360                               sizeof(fatfs_ctx_t) );
[188]1361
[657]1362            // build extended pointer on remote VFS_for_FATFS context
1363            xptr_t remote_vfs_ctx_xp = XPTR( CONFIG_VFS_ROOT_CXY , vfs_fat_ctx_ptr );
[23]1364
[657]1365            // build extended pointer on local VFS_for_FATFS context
1366            xptr_t local_vfs_ctx_xp = XPTR( local_cxy , vfs_fat_ctx_ptr );
1367 
1368            // 3. copy VFS_for_FATFS context from VFS_ROOT cluster to local cluster
1369            hal_remote_memcpy( local_vfs_ctx_xp,
1370                               remote_vfs_ctx_xp,
1371                               sizeof(vfs_ctx_t) );
[101]1372
[657]1373            // update "extend" field in local VFS_for_FATFS context
1374            vfs_fat_ctx_ptr->extend = GET_PTR( local_fatfs_ctx_xp );
[14]1375
[657]1376// check local FATFS and VFS context copies
[669]1377assert( __FUNCTION__, (((fatfs_ctx_t *)vfs_fat_ctx_ptr->extend)->sectors_per_cluster == 8),
1378"illegal FATFS context" );
[101]1379
[657]1380        }
1381        else
[580]1382        {
[657]1383            printk("\n[PANIC] in %s : unsupported VFS type in cluster %x\n",
[580]1384            __FUNCTION__ , local_cxy );
1385            hal_core_sleep();
1386        }
[564]1387
[657]1388        // 4. allocate a local DEVFS context extension,
1389        xptr_t local_devfs_ctx_xp = devfs_ctx_alloc( local_cxy );
[564]1390
[657]1391        // get local pointer on VFS_for_DEVFS context (same in all clusters)
1392        vfs_ctx_t * vfs_dev_ctx_ptr = &fs_context[FS_TYPE_DEVFS];
[188]1393
[657]1394        // build extended pointer on VFS_for_DEVFS extend field in VFS_ROOT cluster
1395        xptr_t remote_extend_xp = XPTR( CONFIG_VFS_ROOT_CXY , &vfs_dev_ctx_ptr->extend );
[188]1396
[657]1397        // get local pointer on DEVFS context in VFS_ROOT cluster
1398        devfs_ctx_t * remote_devfs_ctx_ptr = hal_remote_lpt( remote_extend_xp );
1399
1400        // build extended pointer on FATFS context in VFS_ROOT cluster
1401        xptr_t remote_devfs_ctx_xp = XPTR( CONFIG_VFS_ROOT_CXY , remote_devfs_ctx_ptr );
1402
1403        // 5. copy DEVFS context from VFS_ROOT cluster to local cluster
1404        hal_remote_memcpy( local_devfs_ctx_xp,
1405                           remote_devfs_ctx_xp,
1406                           sizeof(devfs_ctx_t) );
1407
1408        // update "extend" field in local VFS_for_DEVFS context
1409        vfs_dev_ctx_ptr->extend = GET_PTR( local_devfs_ctx_xp );
1410
1411        // get extended pointer on VFS root inode from VFS_ROOT cluster
1412        vfs_root_inode_xp = hal_remote_l64( XPTR( CONFIG_VFS_ROOT_CXY,
1413                                                  &process_zero.vfs_root_xp ) );
1414
1415        // 6. update local process_zero descriptor
1416        process_zero.vfs_root_xp = vfs_root_inode_xp;
1417        process_zero.cwd_xp      = vfs_root_inode_xp;
1418    }
1419
[188]1420    /////////////////////////////////////////////////////////////////////////////////
[564]1421    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
1422                                        (info->x_size * info->y_size) );
[188]1423    barrier_wait( &local_barrier , info->cores_nr );
[204]1424    /////////////////////////////////////////////////////////////////////////////////
[188]1425
[438]1426#if DEBUG_KERNEL_INIT
1427if( (core_lid ==  0) & (local_cxy == 0) ) 
[657]1428printk("\n[%s] exit barrier 7 : VFS & DEVFS contexts replicated in all clusters / cycle %d\n",
1429__FUNCTION__ , (uint32_t)hal_get_cycles() );
[437]1430#endif
[188]1431
1432    /////////////////////////////////////////////////////////////////////////////////
[657]1433    // STEP 8 : In all clusters in parallel, core[0] completes DEVFS initialization.
1434    //          Each core[0] creates the local DEVFS "internal" directory,
1435    //          and creates the pseudo-files for chdevs placed in local cluster.
[188]1436    /////////////////////////////////////////////////////////////////////////////////
1437
1438    if( core_lid == 0 )
1439    {
[657]1440        // get local pointer on local DEVFS context
1441        devfs_ctx_t * ctx = fs_context[FS_TYPE_DEVFS].extend;
[188]1442
[204]1443        // populate DEVFS in all clusters
[657]1444        devfs_local_init( ctx->dev_inode_xp,
1445                          ctx->external_inode_xp );
[188]1446    }
1447
1448    /////////////////////////////////////////////////////////////////////////////////
[564]1449    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 
1450                                        (info->x_size * info->y_size) );
[188]1451    barrier_wait( &local_barrier , info->cores_nr );
[204]1452    /////////////////////////////////////////////////////////////////////////////////
[188]1453
[438]1454#if DEBUG_KERNEL_INIT
1455if( (core_lid ==  0) & (local_cxy == 0) ) 
[657]1456printk("\n[%s] exit barrier 8 : DEVFS initialized in all clusters / cycle %d\n",
[610]1457__FUNCTION__, (uint32_t)hal_get_cycles() );
[437]1458#endif
[188]1459
[623]1460#if( DEBUG_KERNEL_INIT & 1 )
1461if( (core_lid ==  0) & (local_cxy == 0) ) 
1462vfs_display( vfs_root_inode_xp );
1463#endif
1464
[188]1465    /////////////////////////////////////////////////////////////////////////////////
[657]1466    // STEP 9 : core[0] in cluster 0 creates the first user process (process_init).
1467    //          This include the process VMM (GPT and VSL) creation.
1468    //          Finally, it prints the ALMOS-MKH banner.
[188]1469    /////////////////////////////////////////////////////////////////////////////////
1470
[457]1471    if( (core_lid == 0) && (local_cxy == 0) ) 
[188]1472    {
[669]1473        process_init_create();
[188]1474    }
[101]1475
[624]1476#if DEBUG_KERNEL_INIT
1477if( (core_lid ==  0) & (local_cxy == 0) ) 
[657]1478printk("\n[%s] exit barrier 9 : process_init created in cluster 0 / cycle %d\n",
[624]1479__FUNCTION__, (uint32_t)hal_get_cycles() );
1480#endif
1481
[564]1482    if( (core_lid == 0) && (local_cxy == 0) ) 
[188]1483    {
[5]1484        print_banner( (info->x_size * info->y_size) , info->cores_nr );
[623]1485    }
[68]1486
[635]1487#if CONFIG_INSTRUMENTATION_FOOTPRINT
[623]1488if( (core_lid ==  0) & (local_cxy == 0) ) 
[437]1489printk("\n\n***** memory fooprint for main kernel objects\n\n"
[68]1490                   " - thread descriptor  : %d bytes\n"
1491                   " - process descriptor : %d bytes\n"
1492                   " - cluster manager    : %d bytes\n"
1493                   " - chdev descriptor   : %d bytes\n"
1494                   " - core descriptor    : %d bytes\n"
1495                   " - scheduler          : %d bytes\n"
[683]1496                   " - socket descriptor  : %d bytes\n"
[68]1497                   " - rpc fifo           : %d bytes\n"
1498                   " - page descriptor    : %d bytes\n"
[635]1499                   " - mapper descriptor  : %d bytes\n"
1500                   " - vseg descriptor    : %d bytes\n"
[68]1501                   " - ppm manager        : %d bytes\n"
1502                   " - kcm manager        : %d bytes\n"
1503                   " - vmm manager        : %d bytes\n"
[635]1504                   " - vfs inode          : %d bytes\n"
1505                   " - vfs dentry         : %d bytes\n"
1506                   " - vfs file           : %d bytes\n"
1507                   " - vfs context        : %d bytes\n"
1508                   " - xhtab root         : %d bytes\n"
[68]1509                   " - list item          : %d bytes\n"
1510                   " - xlist item         : %d bytes\n"
[564]1511                   " - busylock           : %d bytes\n"
1512                   " - remote busylock    : %d bytes\n"
1513                   " - queuelock          : %d bytes\n"
1514                   " - remote queuelock   : %d bytes\n"
[68]1515                   " - rwlock             : %d bytes\n"
1516                   " - remote rwlock      : %d bytes\n",
[564]1517                   sizeof( thread_t           ),
1518                   sizeof( process_t          ),
1519                   sizeof( cluster_t          ),
1520                   sizeof( chdev_t            ),
1521                   sizeof( core_t             ),
1522                   sizeof( scheduler_t        ),
[662]1523                   sizeof( socket_t           ),
[564]1524                   sizeof( remote_fifo_t      ),
1525                   sizeof( page_t             ),
1526                   sizeof( mapper_t           ),
[635]1527                   sizeof( vseg_t             ),
[564]1528                   sizeof( ppm_t              ),
1529                   sizeof( kcm_t              ),
1530                   sizeof( vmm_t              ),
[635]1531                   sizeof( vfs_inode_t        ),
1532                   sizeof( vfs_dentry_t       ),
1533                   sizeof( vfs_file_t         ),
1534                   sizeof( vfs_ctx_t          ),
1535                   sizeof( xhtab_t            ),
[564]1536                   sizeof( list_entry_t       ),
1537                   sizeof( xlist_entry_t      ),
1538                   sizeof( busylock_t         ),
1539                   sizeof( remote_busylock_t  ),
1540                   sizeof( queuelock_t        ),
1541                   sizeof( remote_queuelock_t ),
1542                   sizeof( rwlock_t           ),
1543                   sizeof( remote_rwlock_t    ));
[406]1544#endif
1545
[683]1546    // number of cycles per TICK (depends on the actual system clock frequency
1547    uint32_t cycles_per_tick = cluster->sys_clk / CONFIG_SCHED_TICKS_PER_SECOND;
1548
[398]1549    // each core activates its private TICK IRQ
[683]1550    dev_pic_enable_timer( cycles_per_tick );
[14]1551
[610]1552    /////////////////////////////////////////////////////////////////////////////////
1553    if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ),
1554                                        (info->x_size * info->y_size) );
1555    barrier_wait( &local_barrier , info->cores_nr );
1556    /////////////////////////////////////////////////////////////////////////////////
1557
[635]1558#if DEBUG_KERNEL_INIT
[610]1559thread_t * this = CURRENT_THREAD;
1560printk("\n[%s] : thread[%x,%x] on core[%x,%d] jumps to thread_idle_func() / cycle %d\n",
1561__FUNCTION__ , this->process->pid, this->trdid,
1562local_cxy, core_lid, (uint32_t)hal_get_cycles() );
[440]1563#endif
1564
[407]1565    // each core jump to thread_idle_func
[50]1566    thread_idle_func();
[14]1567
[610]1568}  // end kernel_init()
1569
Note: See TracBrowser for help on using the repository browser.