Changeset 457


Ignore:
Timestamp:
Aug 2, 2018, 11:47:13 AM (6 years ago)
Author:
alain
Message:

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

Location:
trunk
Files:
243 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r444 r457  
    9090        $(MAKE) -C $(LIBC_PATH) clean
    9191        $(MAKE) -C $(LIBPTHREAD_PATH) clean
     92        $(MAKE) -C $(LIBSEMAPHORE_PATH) clean
    9293        $(MAKE) -C $(LIBALMOSMKH_PATH) clean
    9394        $(MAKE) -C user/init clean
     
    136137        $(MAKE) -C $(LIBALMOSMKH_PATH) headers
    137138        $(MAKE) -C $(LIBPTHREAD_PATH) headers
     139        $(MAKE) -C $(LIBSEMAPHORE_PATH) headers
    138140        $(MAKE) -C $(LIBC_PATH)
    139141        $(MAKE) -C $(LIBALMOSMKH_PATH)
    140142        $(MAKE) -C $(LIBPTHREAD_PATH)
     143        $(MAKE) -C $(LIBSEMAPHORE_PATH)
    141144
    142145#####################################################################
     
    146149        dd if=$@ of=$(DISK_IMAGE) seek=2 conv=notrunc
    147150
    148 #####################################################################
    149 # Rule to generate boot.elf and place it in sector #2 of virtual disk
     151######################################################
     152# Rule to generate HAL objects (depending on HAL_ARCH)
    150153build_hal:
    151154        $(MAKE) -C $(HAL_ARCH)
  • trunk/boot/tsar_mips32/Makefile

    r439 r457  
    5959                                                                boot_utils.h      \
    6060                                                                boot_config.h     \
    61                                                                 $(HAL_ARCH)/core/hal_types.h        \
     61                                                                $(HAL_ARCH)/core/hal_kernel_types.h        \
    6262                                                                ../../hard_config.h
    6363        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
     
    6868                                                                boot_utils.h      \
    6969                                                                boot_config.h     \
    70                                                                 $(HAL_ARCH)/core/hal_types.h        \
     70                                                                $(HAL_ARCH)/core/hal_kernel_types.h        \
    7171                                                                ../../hard_config.h
    7272        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
     
    7777                                                                boot_utils.h      \
    7878                                                                boot_config.h     \
    79                                                                 $(HAL_ARCH)/core/hal_types.h        \
     79                                                                $(HAL_ARCH)/core/hal_kernel_types.h        \
    8080                                                                ../../hard_config.h
    8181        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
     
    8686                                                                boot_utils.h      \
    8787                                                                boot_config.h     \
    88                                                                 $(HAL_ARCH)/core/hal_types.h        \
     88                                                                $(HAL_ARCH)/core/hal_kernel_types.h        \
    8989                                                                ../../hard_config.h
    9090        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
     
    9797                                                                boot_utils.h      \
    9898                                                                boot_config.h     \
    99                                                                 $(HAL_ARCH)/core/hal_types.h        \
     99                                                                $(HAL_ARCH)/core/hal_kernel_types.h        \
    100100                                                                ../../hard_config.h                     
    101101        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
     
    107107                                                                boot_utils.h       \
    108108                                                                boot_tty_driver.h  \
    109                                                                 $(HAL_ARCH)/core/hal_types.h         \
     109                                                                $(HAL_ARCH)/core/hal_kernel_types.h         \
    110110                                                                ../../hard_config.h
    111111        $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $@ $<
     
    122122                                                                boot_mmc_driver.h  \
    123123                                                                boot_config.h      \
    124                                                                 $(HAL_ARCH)/core/hal_types.h         \
     124                                                                $(HAL_ARCH)/core/hal_kernel_types.h         \
    125125                                                                ../../hard_config.h                             
    126126        $(CC) $(BOOT_INCLUDE) $(CFLAGS) $(MACROS) -c -o $@ $<
  • trunk/boot/tsar_mips32/boot.c

    r439 r457  
    7070
    7171#include <elf-types.h>
    72 #include <hal_types.h>
     72#include <hal_kernel_types.h>
    7373
    7474#include <kernel_config.h>
  • trunk/boot/tsar_mips32/boot_bdv_driver.h

    r439 r457  
    1919#define BOOT_BDV_DRIVER_H
    2020
    21 #include <hal_types.h>
     21#include <hal_kernel_types.h>
    2222
    2323/****************************************************************************
  • trunk/boot/tsar_mips32/boot_fat32.h

    r439 r457  
    318318 ****************************************************************************/
    319319
    320 #include <hal_types.h>
     320#include <hal_kernel_types.h>
    321321
    322322typedef struct fat_desc_s
  • trunk/boot/tsar_mips32/boot_hba_driver.h

    r439 r457  
    2727#define BOOT_HBA_DRIVER_H
    2828
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030
    3131/****************************************************************************
  • trunk/boot/tsar_mips32/boot_mmc_driver.h

    r439 r457  
    1313#define _GIET_MMC_DRIVERS_H_
    1414
    15 #include <hal_types.h>
     15#include <hal_kernel_types.h>
    1616
    1717///////////////////////////////////////////////////////////////////////////////////
  • trunk/boot/tsar_mips32/boot_tty_driver.c

    r439 r457  
    2424#include <boot_config.h>
    2525#include <boot_tty_driver.h>
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727#include <boot_utils.h>
    2828
  • trunk/boot/tsar_mips32/boot_tty_driver.h

    r439 r457  
    3333#define BOOT_TTY_DRIVER_H
    3434
    35 #include <hal_types.h>
     35#include <hal_kernel_types.h>
    3636
    3737/****************************************************************************
  • trunk/boot/tsar_mips32/boot_utils.c

    r439 r457  
    2525
    2626#include <boot_tty_driver.h>
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <boot_utils.h>
    2929
  • trunk/boot/tsar_mips32/boot_utils.h

    r439 r457  
    4141#define _BOOT_UTILS_H
    4242
    43 #include <hal_types.h>
     43#include <hal_kernel_types.h>
    4444#include <hard_config.h>
    4545
  • trunk/hal/generic/hal_atomic.h

    r408 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929
    3030//////////////////////////////////////////////////////////////////////////////////////////
  • trunk/hal/generic/hal_context.h

    r408 r457  
    4343 * identified by the <thread> argument. The context is not initialised.
    4444 ****************************************************************************************
     45 * @ thread  : pointer on the thread descriptor.
    4546 * @ return 0 if success / return -1 if failure.
    4647 ***************************************************************************************/
     
    4849
    4950/****************************************************************************************
    50  * This function allocates memory for a CPU context, initialize it from scratch,
    51  * and links it to the thread identified by the <thread> argument.
     51 * This function initializes a CPU context from scratch.
    5252 ****************************************************************************************
    5353 * @ thread  : pointer on the thread descriptor.
    54  * @ return 0 if success / return -1 if failure.
    5554 ***************************************************************************************/
    56 error_t hal_cpu_context_create( struct thread_s * thread );
     55void hal_cpu_context_init( struct thread_s * thread );
    5756
    5857/****************************************************************************************
     
    7170
    7271/****************************************************************************************
     72 * This function is used to implement the exec() system call.
     73 * 1) It initialize the relevant slots of the the calling thread CPU context.
     74 * 2) It call the hal_do_cpu_restore() function to return to user mode and start
     75 *    execution of the new process.
     76 ****************************************************************************************
     77 * @ thread  : pointer on the thread descriptor.
     78 ***************************************************************************************/
     79void hal_cpu_context_exec( struct thread_s * thread );
     80
     81/****************************************************************************************
    7382 * This function display some slots of the CPU context.
    74  * - For the MIPS32 :
    75  *   . GPR : gp_28 , sp_29 , ra_31
    76  *   . CP0 : c0_sr , c0_th , c0_epc
    77  *   . CP2 : c2_ptpr , c2-mode
    78  * - For X86 TODO :
    7983 ****************************************************************************************
    8084 * @ thread_xp  : extended pointer on the thread descriptor.
     
    103107 ***************************************************************************************/
    104108error_t hal_fpu_context_alloc( struct thread_s * thread );
     109
     110/****************************************************************************************
     111 * This function initializes a FPU context from scratch.
     112 ****************************************************************************************
     113 * @ thread  : pointer on the thread descriptor.
     114 ***************************************************************************************/
     115void hal_fpu_context_init( struct thread_s * thread );
    105116
    106117/****************************************************************************************
  • trunk/hal/generic/hal_exception.h

    r455 r457  
    2525#define _HAL_EXCEPTION_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828
    2929//////////////////////////////////////////////////////////////////////////////////////////
  • trunk/hal/generic/hal_gpt.h

    r432 r457  
    2525#define _GPT_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828
    2929/////////////////////////////////////////////////////////////////////////////////////////
  • trunk/hal/generic/hal_interrupt.h

    r408 r457  
    2525#define _HAL_INTERRUPT_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828
    2929///////////////////////////////////////////////////////////////////////////////////////
  • trunk/hal/generic/hal_irqmask.h

    r279 r457  
    2626#define  _HAL_IRQMASK_H_
    2727
    28 #include <hal_types.h>
     28#include <hal_shared_types.h>
    2929
    3030
  • trunk/hal/generic/hal_ppm.h

    r409 r457  
    2626#define _HAL_PPM_H_
    2727
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <boot_info.h>
    3030
  • trunk/hal/generic/hal_remote.h

    r407 r457  
    2626#define  _HAL_REMOTE_H_
    2727
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929
    3030//////////////////////////////////////////////////////////////////////////////////////////
  • trunk/hal/generic/hal_special.h

    r408 r457  
    2525#define  _HAL_CPU_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_shared_types.h>
     28#include <hal_kernel_types.h>
    2829
    2930/****  Forward declarations  ***/
  • trunk/hal/generic/hal_switch.h

    r408 r457  
    2828
    2929/*************************************************************************************
    30  * The hal_do_cpu_switch() function is an assembly level function, called by the
    31  * sched_yield() function, to make a CPU context switch.
    32  * The current thread CPU context is identified by the <ctx_current> pointer.
    33  * The new thread CPU context is identified by the <ctx_next> pointer.
     30 * This assembly level function is called by the sched_yield() function,
     31 * to make a CPU context switch.
     32 * The current thread CPU context is identified by the <ctx_old> pointer.
     33 * The new thread CPU context is identified by the <ctx_new> pointer.
    3434 * The architecture specific hal_cpu_context_t structure used to store a CPU context
    3535 * is defined in the architecture specific hal_context.c file.
     
    4545
    4646/*************************************************************************************
    47  * The hal_do_cpu_save() function is an assembly level function, called by the
    48  * hal_cpu_context_save() functio to save the calling CPU register values to a
    49  * CPU context identified by the <ctx> pointer.
     47 * This assembly level function is called by the hal_cpu_context_fork() function.
     48 * It save the calling CPU register values to a CPU context identified by <ctx>.
    5049 * This function does NOT modify any register before saving values into context.
    5150 * The architecture specific hal_cpu_context_t structure used to store a CPU context
     
    5756void hal_do_cpu_save( void * ctx );
    5857
     58/*************************************************************************************
     59 * This assembly level function, is called by the hal_cpu_context_exec() function.
     60 * It restore the calling CPU register values from a CPU context identified by <ctx>.
     61 * The architecture specific hal_cpu_context_t structure used to store a CPU context
     62 * is defined in the architecture specific hal_context.c file.
     63 * When the restore is completed, it simply jumps to the address contained in ra_31.
     64 * In ALMOS-MKH, ra_31 must contain a pointer on the eret() function, and c0_epc
     65 * must contain the new main thread entry point.
     66 *************************************************************************************
     67 * @ ctx     : local pointer on CPU context.
     68 ************************************************************************************/
     69void hal_do_cpu_restore( void * ctx );
     70
    5971#endif  /* _HAL_SWITCH_H_ */
  • trunk/hal/generic/hal_syscall.h

    r408 r457  
    2525#define _HAL_KERNEL_SYSCALL_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828
    2929///////////////////////////////////////////////////////////////////////////////////////
  • trunk/hal/generic/hal_user.h

    r445 r457  
    2525#define _HAL_USER_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_shared_types.h>
    2828
    2929//////////////////////////////////////////////////////////////////////////////////////////
  • trunk/hal/generic/hal_uspace.h

    r407 r457  
    2525#define  _HAL_USPACE_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828
    2929//////////////////////////////////////////////////////////////////////////////////////////
  • trunk/hal/generic/hal_vmm.h

    r411 r457  
    2525#define _HAL_PPM_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <boot_info.h>
    2929
  • trunk/hal/tsar_mips32/Makefile

    r444 r457  
    7272                                $(HAL_ARCH)/drivers/%.h      \
    7373                                $(KERNEL)/kernel_config.h    \
    74                                 $(HAL_ARCH)/core/hal_types.h
     74                                $(HAL_ARCH)/core/hal_kernel_types.h
    7575        $(CC) $(HAL_INCLUDE) $(CFLAGS)  -c -o $@ $<
    7676
     
    8080                                $(HAL)/generic/%.h           \
    8181                                $(KERNEL)/kernel_config.h    \
    82                                 $(HAL_ARCH)/core/hal_types.h
     82                                $(HAL_ARCH)/core/hal_kernel_types.h
    8383        $(CC) $(HAL_INCLUDE) $(CFLAGS) -c -o $@ $<
    8484
     
    8686                                      $(HAL_ARCH)/core/hal_kentry.h \
    8787                                      $(KERNEL)/kernel_config.h     \
    88                                       $(HAL_ARCH)/core/hal_types.h
     88                                      $(HAL_ARCH)/core/hal_kernel_types.h
    8989        $(CC) $(HAL_INCLUDE) $(CFLAGS) -c -o $@ $<
    9090
  • trunk/hal/tsar_mips32/core/hal_atomic.c

    r62 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525
    2626////////////////////////////////////
  • trunk/hal/tsar_mips32/core/hal_context.c

    r432 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_switch.h>
    2626#include <memcpy.h>
     
    136136}   // end hal_cpu_context_alloc()
    137137
    138 ///////////////////////////////////////////////////
    139 // The following context slots are initialised :
     138/////////////////////////////////////////////////
     139// The following context slots are initialised
    140140// GPR : a0_04 / sp_29 / ra_31
    141141// CP0 : c0_sr / c0_th / c0_epc
    142142// CP2 : c2_ptpr / c2_mode
    143 ///////////////////////////////////////////////////
    144 error_t hal_cpu_context_create( thread_t * thread )
    145 {
    146     // allocate memory for a CPU context
    147     error_t error = hal_cpu_context_alloc( thread );
    148 
    149     if( error ) return error;
    150 
     143/////////////////////////////////////////////////
     144void hal_cpu_context_init( thread_t * thread )
     145{
    151146    hal_cpu_context_t * context = (hal_cpu_context_t *)thread->cpu_context;
     147
     148    assert( (context != NULL ), __FUNCTION__, "CPU context not allocated" );
    152149
    153150    // initialisation depends on thread type
     
    173170        context->c2_mode = 0x3;
    174171    }
    175 
    176     return 0;
    177 
    178 }  // end hal_cpu_context_create()
     172}  // end hal_cpu_context_init()
    179173
    180174////////////////////////////////////////////
     
    243237        assert( (current == child_ptr) , __FUNCTION__ , "current = %x / child = %x\n");
    244238    }
    245 
    246239}  // end hal_cpu_context_fork()
     240
     241//////////////////////////////////////////////
     242void hal_cpu_context_exec( thread_t * thread )
     243{
     244    // re_initialize CPU context
     245    hal_cpu_context_init( thread );
     246
     247    // restore CPU registers ... and jump
     248    hal_do_cpu_restore( (hal_cpu_context_t *)thread->cpu_context );
     249
     250} // end hal_cpu_context_exec()
    247251
    248252/////////////////////////////////////////////////
     
    312316
    313317}   // end hal_fpu_context_alloc()
     318
     319//////////////////////////////////////////////
     320void hal_fpu_context_init( thread_t * thread )
     321{
     322    hal_fpu_context_t * context = thread->fpu_context;
     323
     324    assert( (context != NULL) , __FUNCTION__ , "fpu context not allocated" );
     325
     326    memset( context , 0 , sizeof(hal_fpu_context_t) );
     327}
    314328
    315329//////////////////////////////////////////
  • trunk/hal/tsar_mips32/core/hal_drivers.c

    r407 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <chdev.h>
    2424#include <hal_drivers.h>
  • trunk/hal/tsar_mips32/core/hal_exception.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_irqmask.h>
    2626#include <hal_special.h>
     
    134134        core_t   * core = this->core;
    135135
    136     // enable FPU
     136    // enable FPU (in core SR)
    137137        hal_fpu_enable();
    138138
    139     // save FPU context in current owner thread if required
     139    // save FPU register values in current owner thread if required
    140140        if( core->fpu_owner != NULL )
    141141    {
    142142        if( core->fpu_owner != this )
    143143            {
     144            // save the FPU registers to current owner thread context
    144145                    hal_fpu_context_save( XPTR( local_cxy , core->fpu_owner ) );
     146
     147            // restore FPU registers from requesting thread context
     148                hal_fpu_context_restore( this->fpu_context );
     149
     150            // attach the FPU to the requesting thread
     151                core->fpu_owner = this;
    145152        }
    146153        }
    147 
    148     // attach the FPU to the requesting thread
    149         hal_fpu_context_restore( this->fpu_context );
    150         core->fpu_owner = this;
     154    else
     155    {
     156        // restore FPU registers from requesting thread context
     157            hal_fpu_context_restore( this->fpu_context );
     158
     159        // attach the FPU to the requesting thread
     160            core->fpu_owner = this;
     161    }
    151162
    152163        return EXCP_NON_FATAL;
     
    206217uint32_t cycle = (uint32_t)hal_get_cycles();
    207218if( DEBUG_HAL_EXCEPTIONS < cycle )
    208 printk("\n[DBG] %s : thread %x enter / is_ins %d / %s / vaddr %x / cycle %d\n",
    209 __FUNCTION__, this, is_ins, hal_mmu_exception_str(excp_code), bad_vaddr, cycle );
     219printk("\n[DBG] %s : thread %x in process %x enter / is_ins %d / %s / vaddr %x / cycle %d\n",
     220__FUNCTION__, this->trdid, process->pid, is_ins, hal_mmu_exception_str(excp_code), bad_vaddr, cycle);
    210221#endif
    211222
     
    235246cycle = (uint32_t)hal_get_cycles();
    236247if( DEBUG_HAL_EXCEPTIONS < cycle )
    237 printk("\n[DBG] %s : thread %x exit / page-fault handled for vaddr = %x\n",
    238 __FUNCTION__ , this , bad_vaddr );
     248printk("\n[DBG] %s : thread %x in process %x exit / page-fault handled for vaddr = %x\n",
     249__FUNCTION__, this->trdid, process->pid, bad_vaddr );
    239250#endif
    240251 
     
    275286cycle = (uint32_t)hal_get_cycles();
    276287if( DEBUG_HAL_EXCEPTIONS < cycle )
    277 printk("\n[DBG] %s : thread %x exit / copy-on-write handled for vaddr = %x\n",
    278 __FUNCTION__ , this , bad_vaddr );
     288printk("\n[DBG] %s : thread %x in process %x exit / copy-on-write handled for vaddr = %x\n",
     289__FUNCTION__, this->trdid, process->pid, bad_vaddr );
    279290#endif
    280291
     
    300311        {
    301312            assert( false , __FUNCTION__ ,
    302             "thread %x / core[%x,%d] / epc %x / vaddr %x / cycle %d\n",
    303             this, local_cxy, this->core->lid, excPC, bad_vaddr, (uint32_t)hal_get_cycles() );
     313            "thread %x in process %x / core[%x,%d] / epc %x / vaddr %x / cycle %d\n",
     314            this->trdid, this->process->pid, local_cxy, this->core->lid,
     315            excPC, bad_vaddr, (uint32_t)hal_get_cycles() );
    304316
    305317            return EXCP_KERNEL_PANIC;
     
    398410uint32_t cycle = (uint32_t)hal_get_cycles();
    399411if( DEBUG_HAL_EXCEPTIONS < cycle )
    400 printk("\n[DBG] %s : thread %x enter / core[%x,%d] / pid %x / epc %x / xcode %x / cycle %d\n",
    401 __FUNCTION__, this, local_cxy, this->core->lid, this->process->pid, excPC, excCode, cycle );
     412printk("\n[DBG] %s : thread %x in process %x enter / core[%x,%d] / epc %x / xcode %x / cycle %d\n",
     413__FUNCTION__, this->trdid, this->process->pid, local_cxy, this->core->lid, excPC, excCode, cycle );
    402414#endif
    403415
     
    458470cycle = (uint32_t)hal_get_cycles();
    459471if( DEBUG_HAL_EXCEPTIONS < cycle )
    460 printk("\n[DBG] %s : thread %x exit / core[%x,%d] / pid %x / epc %x / xcode %x / cycle %d\n",
    461 __FUNCTION__, this, local_cxy, this->core->lid, this->process->pid, excPC, excCode, cycle );
     472printk("\n[DBG] %s : thread %x in process %x exit / core[%x,%d] / epc %x / xcode %x / cycle %d\n",
     473__FUNCTION__, this->trdid, this->process->pid, local_cxy, this->core->lid, excPC, excCode, cycle );
    462474#endif
    463475
  • trunk/hal/tsar_mips32/core/hal_gpt.c

    r445 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_gpt.h>
    2626#include <hal_special.h>
  • trunk/hal/tsar_mips32/core/hal_interrupt.c

    r435 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <kernel_config.h>
  • trunk/hal/tsar_mips32/core/hal_irqmask.c

    r285 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
     26#include <hal_shared_types.h>
    2627
    2728//////////////////////////////////////////
  • trunk/hal/tsar_mips32/core/hal_ppm.c

    r443 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_ppm.h>
    2727#include <hal_special.h>
  • trunk/hal/tsar_mips32/core/hal_remote.c

    r313 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_irqmask.h>
    2727
  • trunk/hal/tsar_mips32/core/hal_special.c

    r425 r457  
    2323
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <core.h>
  • trunk/hal/tsar_mips32/core/hal_switch.S

    r408 r457  
    2626    .global  hal_do_cpu_switch
    2727    .global  hal_do_cpu_save
     28    .global  hal_do_cpu_restore
    2829
    2930    .set     noat
     
    9091        sw      $27,  33*4($26)           /* save c2_mode to slot 33 */
    9192
     93    sync                           
     94
    9295    /* restore new thread context */
    9396 
     
    144147        mtc2    $27,  $1                   /* restore c2_mode from slot 33 */
    145148    mtc0        $26,  $12                  /* restore c0_sr from slot 34 */
    146 
    147     sync                           
    148149
    149150    jr      $31                        /* return to caller */
     
    211212    nop
    212213
     214#---------------------------------------------------------------------------------
     215# The hal_do_cpu_restore()function makes the following assumption:
     216# - register $4 contains a pointer on the target thread context.
     217#---------------------------------------------------------------------------------
     218hal_do_cpu_restore:
     219
     220    move    $26,  $4                  /* $26 <= &context */
     221
     222    lw      $27,   0*4($26)         
     223    mtc0    $27,   $14                 /* restore C0_epc from slot 0 */
     224
     225    lw      $1,    1*4($26)         
     226    lw      $2,    2*4($26)         
     227    lw      $3,    3*4($26)         
     228    lw      $4,    4*4($26)         
     229    lw      $5,    5*4($26)         
     230    lw      $6,    6*4($26)         
     231    lw      $7,    7*4($26)         
     232    lw      $8,    8*4($26)         
     233    lw      $9,    9*4($26)         
     234    lw      $10,  10*4($26)         
     235    lw      $11,  11*4($26)         
     236    lw      $12,  12*4($26)         
     237    lw      $13,  13*4($26)         
     238    lw      $14,  14*4($26)         
     239    lw      $15,  15*4($26)         
     240        lw      $16,  16*4($26)         
     241        lw      $17,  17*4($26)         
     242    lw      $18,  18*4($26)         
     243    lw      $19,  19*4($26)         
     244    lw      $20,  20*4($26)         
     245    lw      $21,  21*4($26)         
     246    lw      $22,  22*4($26)         
     247    lw      $23,  23*4($26)         
     248    lw      $24,  24*4($26)         
     249    lw      $25,  25*4($26)         
     250
     251    lw      $27,  26*4($26)         
     252    mthi    $27                        /* restore hi from slot 26 */
     253    lw      $27,  27*4($26)         
     254    mtlo    $27                        /* restore lo from slot 27 */
     255
     256        lw      $28,  28*4($26)         
     257        lw      $29,  29*4($26)         
     258        lw      $30,  30*4($26)         
     259        lw      $31,  31*4($26)            /* restore ra from slot 31 */
     260
     261        lw      $27,  32*4($26)
     262        mtc2    $27,  $0                   /* restore c2_ptpr from slot 32 */
     263
     264        lw      $27,  35*4($26)     
     265    mtc0        $27,  $4, 2                /* restore c0_th from slot 35 */
     266
     267        lw      $27,  33*4($26)
     268        lw      $26,  34*4($26)
     269
     270        mtc2    $27,  $1                   /* restore c2_mode from slot 33 */
     271    mtc0        $26,  $12                  /* restore c0_sr from slot 34 */
     272
     273    jr      $31                        /* return to caller */
     274    nop
     275
    213276        .set reorder                   
    214277    .set at                         
  • trunk/hal/tsar_mips32/core/hal_syscall.c

    r425 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_syscall.h>
    2626#include <do_syscall.h>
     
    4848    enter_uzone = (uint32_t *)this->uzone_current;
    4949
    50 //printk("\n@@@ enter %s : thread = %x / enter_uzone = %x / EPC = %x\n",
    51 //__FUNCTION__ , this , enter_uzone , enter_uzone[UZ_EPC] );
    52 
    5350    // get syscall arguments from uzone
    5451        service_num = enter_uzone[UZ_V0];
     
    7168    exit_uzone = (uint32_t *)this->uzone_current;
    7269
    73 //printk("\n@@@ exit %s : thread = %x / exit_uzone = %x / EPC = %x\n",
    74 //__FUNCTION__ , this , exit_uzone , exit_uzone[UZ_EPC] );
    75 
    7670    // set return value to uzone
    7771        exit_uzone[UZ_V0] = retval;
  • trunk/hal/tsar_mips32/core/hal_uspace.c

    r425 r457  
    2525#include <errno.h>
    2626#include <vmm.h>
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <hal_uspace.h>
    2929#include <hal_irqmask.h>
  • trunk/hal/tsar_mips32/core/hal_vmm.c

    r411 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_vmm.h>
    2727#include <hal_gpt.h>
  • trunk/hal/tsar_mips32/drivers/soclib_pic.c

    r451 r457  
    137137#endif
    138138
    139     // analyse status and handle up to 3 pending IRQ (one WTI, one HWI, one PTI)
     139    // analyse status and handle up to 3 pending IRQs (one WTI, one HWI, one PTI)
    140140
    141141    if( wti_status )          // pending WTI
     
    150150#if DEBUG_HAL_IRQS
    151151if (DEBUG_HAL_IRQS < cycle )
    152 printk("\n[DBG] %s : core[%x,%d] received an IPI\n", __FUNCTION__ , local_cxy , core->lid );
     152printk("\n[DBG] %s : core[%x,%d] handling IPI\n", __FUNCTION__ , local_cxy , core->lid );
    153153#endif
    154154            // acknowledge IRQ (this require an XCU read)
     
    156156
    157157            // check RPC FIFO,  and activate or create a RPC thread
    158             // condition is always true, but we must use the ack value
     158            // condition is always true, but we use the ack value
     159            // to avoid a GCC warning
    159160            if( ack + 1 ) rpc_check();
    160161        }
     
    182183#if DEBUG_HAL_IRQS
    183184if (DEBUG_HAL_IRQS < cycle )
    184 printk("\n[DBG] %s : core[%x,%d] received external WTI %d\n",
     185printk("\n[DBG] %s : core[%x,%d] handling external WTI %d\n",
    185186__FUNCTION__ , local_cxy , core->lid , index );
    186187#endif
     
    216217#if DEBUG_HAL_IRQS
    217218if (DEBUG_HAL_IRQS < cycle )
    218 printk("\n[DBG] %s : core[%x,%d] received HWI %d\n",
     219printk("\n[DBG] %s : core[%x,%d] handling HWI %d\n",
    219220__FUNCTION__ , local_cxy , core->lid , index );
    220221#endif
     
    232233#if DEBUG_HAL_IRQS
    233234if (DEBUG_HAL_IRQS < cycle )
    234 printk("\n[DBG] %s : core[%x,%d] received PTI %d\n",
     235printk("\n[DBG] %s : core[%x,%d] handling PTI %d\n",
    235236__FUNCTION__ , core->lid , local_cxy , index );
    236237#endif
     
    239240
    240241        // execute all actions related to TICK event
    241         // condition is always true, but we must use the ack value
     242        // condition is always true, but we use the ack value
     243        // to avoid a GCC warning
    242244        if( ack + 1 ) core_clock( core );
    243245        }
     
    515517{
    516518    // calling core local index
    517     lid_t  lid = CURRENT_CORE->lid;
     519    lid_t  lid = CURRENT_THREAD->core->lid;
    518520
    519521    // get XCU segment base
     
    533535{
    534536    // calling core local index
    535     lid_t  lid = CURRENT_CORE->lid;
     537    lid_t  lid = CURRENT_THREAD->core->lid;
    536538
    537539    // get XCU segment base
  • trunk/hal/tsar_mips32/drivers/soclib_tty.c

    r451 r457  
    272272    xptr_t       parent_main_xp;    // local pointer on parent process main thread
    273273
    274     // get TXT chdev channel, direction and server thread
     274    // get TXT chdev channel, direction, server thread, and server core
    275275    channel    = chdev->channel;
    276276    is_rx      = chdev->is_rx;
     
    455455                thread_unblock( XPTR( local_cxy , server ) , THREAD_BLOCKED_ISR );
    456456
    457                 // send IPI to core running server thread
    458                 dev_pic_send_ipi( local_cxy , server_lid );
     457                // send IPI to core running server thread if required
     458                if( server_lid != CURRENT_THREAD->core->lid )
     459                {
     460                    dev_pic_send_ipi( local_cxy , server_lid );
     461                }
    459462            }
    460463            else
     
    501504        thread_unblock( XPTR( local_cxy , server ) , THREAD_BLOCKED_ISR );
    502505
    503         // send IPI to core running server thread
    504         dev_pic_send_ipi( local_cxy , server_lid );
     506        // send IPI to core running server thread if required
     507        if( server_lid != CURRENT_THREAD->core->lid )
     508        {
     509            dev_pic_send_ipi( local_cxy , server_lid );
     510        }
    505511
    506512    }  // end TX
  • trunk/hal/tsar_mips32/drivers/soclib_tty.h

    r436 r457  
    22 * soclib_tty.c - soclib tty driver definition.
    33 *
    4  * Author  Alain Greiner (2016)
     4 * Author  Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c)  UPMC Sorbonne Universites
     
    2929/****************************************************************************************
    3030 * This driver supports the vci_tty_tsar component.
    31  * It implements the generic TXT device API:
     31 * Regarding read/write request, it implements the generic TXT device API:
    3232 * - transfer one single character from TTY to command "buffer" if to_mem is non-zero.
    3333 * - transfer "count" characters from command "buffer" to TTY if "to_mem is zero.
     34 * It handles asynchronous control characters (^C / ^Z), that are translated to signals
     35 * transmited to the TXT owner process (foreground process).
    3436 ***************************************************************************************/
    3537
     
    101103/****************************************************************************************
    102104 * This ISR is executed to handle both the TTY_TX_IRQ and the TTY_RX_IRQ, even if
    103  *   The RX_IRQ is activated as soon as the TTY_STATUS_RX_FULL bit is 1 in the
     105 * there is two different channel devices for TX and RX transfers.
     106 *
     107 * As the <chdev> argument is a local pointer, this ISR is always executed by a core
     108 * that is in the same cluster as the core running the DEV server thread.
     109 *
     110 * - The RX_IRQ is activated as soon as the TTY_STATUS_RX_FULL bit is 1 in the
    104111 *   TTY_STATUS register, when the TTY_RX_IRQ_ENABLE is non zero, indicating that
    105112 *   the TTY_READ buffer is full and can be read.
    106  *   The TX_IRQ is activated as soon as the TTY_STATUS_TX_FULL bit is 0 in the
     113 * - The TX_IRQ is activated as soon as the TTY_STATUS_TX_FULL bit is 0 in the
    107114 *   TTY_STATUS register, when the TTY_TX_IRQ_ENABLE is non zero, indicating that
    108115 *   the TTY_WRITE buffer is empty, and can be written.
    109  * WARNING : In ALMOS-MKH, the RX_IRQ is always enabled to catch the control signals,
     116 *
     117 * The RX_IRQ is always enabled to catch the control characters (^Z / ^C),
    110118 * but the TX_IRQ is dynamically enabled by the TXT_WRITE command, and disabled when
    111119 * the command is completed.
    112120 *
    113  * 1) The ISR first read the TTY_STATUS to get the current state of the TTY_READ and
    114  *   the TTY_WRITE buffers.
     121 * For normal characters The ISR uses two private TTY_RX and TTY_TX software FIFOs
     122 * (two FIFOs per channel) to communicates with the DEV server thread executing the
     123 * soclib_tty_cmd() function.
     124
     125 * For an RX transfer, this ISR executes a while loop moving bytes until the source
     126 * TTY_READ buffer is empty:
     127 *   1) The ISR read one byte from the TTY_READ register and acknowledge the RX_IRQ.
     128 *   2) if the byte is a ^Z character, it uses a multicast RPC to block all treads of
     129 *      the TXT owner process, and transfer TXT ownership to another process of the group.
     130 *   3) if the byte is a ^C character, it removes the process from the TXT group, and send
     131 *      a multicast RPC to delete all threads of the TXT owner process.
     132 *   4) if the byte is a normal character and the destination TTY_RX_FIFO is not full,
     133 *      it writes the byte to this FIFO, unblock the TXT_RX server thread, and send an IPI
     134 *      to this server thread (only if it is running on another core than the ISR).
     135 *   5) It discards the byte if the TTY_RX_FIFO is full, with a warning message on TXT0.
    115136 *
    116  * 2) It try to read the first command registered in the server thread queue associated
    117  *    to the TTY channel
    118  *
    119  * 2) The ISR handles the RX when the TTY_READ buffer is full :
    120  *   . it read the available character from the TTY_READ buffer, and this
    121  *     acknowledges the RX_IRQ.
    122  *   . if it is a control character ( ^C / ^D / ^Z ) it translate it to the proper
    123  *     signal and execute the relevant sigaction for the foreground process.
    124  *   . if it is a normal character, it try to get the first command registered in the
    125  *     server thread queue. If it is a TXT_READ, it returns this character to the
    126  *     command buffer in the client thread.
    127  *
    128  * 3) The ISR handles the TX when the TTY_WRITE buffer is empty and a TXT_WRITE
    129  *   . it try to get it copies the
    130  *     character to the command buffer, acknowledges the TTY_RX_IRQ, and unblock the
    131  *     associated server thread.
    132      
    133  *   . the control characters ^C / ^D / ^Z  are directly handled by the ISR and
    134  *     translated to the foreground process.
    135 
    136  * - the
    137  the TXT_READ and TXT_WRITE commands.
    138  * It gets the command arguments from the first client thread in the TXT chdev queue:
    139  * - if TXT_READ, it transfers one byte from the TTY_READ_REG to the command buffer.
    140  *   It simply returns for retry if TTY_READ_REG is empty.
    141  * - if TXT_WRITE, it tries to transfer several bytes from the command buffer to the
    142  *   TTY_WRITE_REG. If the TTY_WRITE_REG is full, it updates the "count" and "buffer"
    143  *   command arguments and returns for retry.
    144  * When the I/O operation is completed, it sets the status field in the command, unblocks
    145  * the server thread, and unblocks the client thread.
     137 * For a TX transfer, this ISR executes a while loop moving bytes until the source
     138 * TTY_TX_FIFO is empty:
     139 *   1) if the destination TTY_WRITE register is not full, it moves the byte from the
     140 *      TTY_TX_FIFO to the TTY_WRITE register.
     141 *   2) if the TTY_WRITE register is full, it polls (busy waiting) the TTY_STATUS register,
     142 *      until the TTY_WRITE register is empty.
     143 *   3) when the source TTY_TX_FIFO is empty, this ISR disable the TTY_TX_IRQ, unblock
     144 *      the TXT_TX server thread, and send an IPI to this server thread (only if it is
     145 *      running on another core than the ISR).
    146146 ****************************************************************************************
    147147 * @ chdev     : local pointer on TXT chdev descriptor.
  • trunk/hal/x86_64/Makefile

    r444 r457  
    7272                                drivers/%.h \
    7373                                $(KERNEL)/kernel_config.h             \
    74                                 core/hal_types.h
     74                                core/hal_kernel_types.h
    7575        $(CC) $(HAL_INCLUDE) $(CFLAGS)  -c -o $@ $<
    7676
     
    8080                                $(HAL)/generic/%.h             \
    8181                                $(KERNEL)/kernel_config.h             \
    82                                 core/hal_types.h
     82                                core/hal_kernel_types.h
    8383        $(CC) $(HAL_INCLUDE) $(CFLAGS) -c -o $@ $<
    8484
     
    8888                                core/hal_segmentation.h \
    8989                                $(KERNEL)/kernel_config.h              \
    90                                 core/hal_types.h
     90                                core/hal_kernel_types.h
    9191        $(CC) $(HAL_INCLUDE) $(CFLAGS) -c -o $@ $<
    9292
     
    9696                                core/hal_segmentation.h \
    9797                                $(KERNEL)/kernel_config.h              \
    98                                 core/hal_types.h
     98                                core/hal_kernel_types.h
    9999        $(CC) $(HAL_INCLUDE) $(CFLAGS) -c -o $@ $<
    100100
     
    107107                                core/hal_internal.h     \
    108108                                $(KERNEL)/kernel_config.h               \
    109                                 core/hal_types.h
     109                                core/hal_kernel_types.h
    110110        $(CC) $(HAL_INCLUDE) $(CFLAGS) -c -o $@ $<
    111111
     
    114114                                core/hal_segmentation.h \
    115115                                $(KERNEL)/kernel_config.h              \
    116                                 core/hal_types.h
     116                                core/hal_kernel_types.h
    117117        $(CC) $(HAL_INCLUDE) $(CFLAGS) -c -o $@ $<
    118118
     
    121121                                core/hal_boot.h        \
    122122                                $(KERNEL)/kernel_config.h              \
    123                                 core/hal_types.h
     123                                core/hal_kernel_types.h
    124124        $(CC) $(HAL_INCLUDE) $(CFLAGS) -c -o $@ $<
    125125
     
    127127                                core/hal_acpi.h        \
    128128                                $(KERNEL)/kernel_config.h              \
    129                                 core/hal_types.h
     129                                core/hal_kernel_types.h
    130130        $(CC) $(HAL_INCLUDE) $(CFLAGS) -c -o $@ $<
    131131
     
    133133                                core/hal_apic.h        \
    134134                                $(KERNEL)/kernel_config.h              \
    135                                 core/hal_types.h
     135                                core/hal_kernel_types.h
    136136        $(CC) $(HAL_INCLUDE) $(CFLAGS) -c -o $@ $<
    137137
    138138$(HAL_ARCH)/build/core/x86_printf.o:  core/x86_printf.c      \
    139139                                $(KERNEL)/kernel_config.h              \
    140                                 core/hal_types.h
     140                                core/hal_kernel_types.h
    141141        $(CC) $(HAL_INCLUDE) $(CFLAGS) -c -o $@ $<
    142142
  • trunk/hal/x86_64/core/hal_acpi.c

    r348 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <hal_boot.h>
    2424#include <hal_acpi.h>
  • trunk/hal/x86_64/core/hal_apic.c

    r327 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <hal_boot.h>
    2424#include <hal_register.h>
  • trunk/hal/x86_64/core/hal_atomic.c

    r234 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <hal_internal.h>
    2424
  • trunk/hal/x86_64/core/hal_context.c

    r368 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <memcpy.h>
    2424#include <thread.h>
  • trunk/hal/x86_64/core/hal_drivers.c

    r346 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <chdev.h>
    2424#include <hal_drivers.h>
  • trunk/hal/x86_64/core/hal_exception.c

    r403 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <hal_irqmask.h>
    2424#include <hal_exception.h>
  • trunk/hal/x86_64/core/hal_gpt.c

    r408 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <hal_boot.h> /* XXX */
    2424#include <hal_gpt.h>
  • trunk/hal/x86_64/core/hal_init.c

    r365 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <hal_boot.h>
    2424#include <hal_multiboot.h>
  • trunk/hal/x86_64/core/hal_interrupt.c

    r344 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <kernel_config.h>
    2424#include <thread.h>
  • trunk/hal/x86_64/core/hal_irqmask.c

    r370 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <hal_internal.h>
    2424#include <hal_segmentation.h>
  • trunk/hal/x86_64/core/hal_ppm.c

    r407 r457  
    2121
    2222#include <kernel_config.h>
    23 #include <hal_types.h>
     23#include <hal_kernel_types.h>
    2424#include <hal_ppm.h>
    2525#include <hal_special.h>
  • trunk/hal/x86_64/core/hal_remote.c

    r314 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <hal_internal.h>
    2424
  • trunk/hal/x86_64/core/hal_special.c

    r371 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <hal_apic.h>
    2424#include <hal_special.h>
  • trunk/hal/x86_64/core/hal_syscall.c

    r145 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_syscall.h>
    2626#include <do_syscall.h>
  • trunk/hal/x86_64/core/hal_types.h

    r407 r457  
    11/*
    2  * hal_types.h - common kernel types for x86_64
     2 * hal_kernel_types.h - common kernel types for x86_64
    33 *
    44 * Author  Alain Greiner (2016)
  • trunk/hal/x86_64/core/hal_uspace.c

    r407 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <hal_irqmask.h>
  • trunk/hal/x86_64/core/x86_printf.c

    r242 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <hal_boot.h>
    2424#include <hal_internal.h>
  • trunk/hal/x86_64/drivers/ioc_ata.h

    r215 r457  
    2424
    2525#include <chdev.h>
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727
    2828void ioc_ata_init(chdev_t *chdev);
  • trunk/hal/x86_64/drivers/pic_apic.c

    r404 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <chdev.h>
    2424#include <pic_apic.h>
  • trunk/hal/x86_64/drivers/pic_apic.h

    r280 r457  
    2323#define _PIC_APIC_H_
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626
    2727void pic_apic_init(chdev_t *pic);
  • trunk/kernel/Makefile

    r444 r457  
    177177              build/syscalls/sys_thread_wakeup.o   \
    178178              build/syscalls/sys_trace.o           \
    179               build/syscalls/sys_fg.o
     179              build/syscalls/sys_fg.o              \
     180              build/syscalls/sys_is_fg.o
    180181
    181182VFS_OBJS    = build/fs/vfs.o              \
     
    228229                        kern/%.h                      \
    229230                        kernel_config.h               \
    230                         $(HAL_ARCH)/core/hal_types.h
     231                        $(HAL_ARCH)/core/hal_kernel_types.h
    231232        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
    232233
     
    237238                        devices/%.h                   \
    238239                        kernel_config.h               \
    239                         $(HAL_ARCH)/core/hal_types.h
     240                        $(HAL_ARCH)/core/hal_kernel_types.h
    240241        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
    241242
     
    245246                        mm/%.h                        \
    246247                        kernel_config.h               \
    247                         $(HAL_ARCH)/core/hal_types.h
     248                        $(HAL_ARCH)/core/hal_kernel_types.h
    248249        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
    249250
     
    253254                        libk/%.h                      \
    254255                        kernel_config.h               \
    255                         $(HAL_ARCH)/core/hal_types.h
     256                        $(HAL_ARCH)/core/hal_kernel_types.h
    256257        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
    257258
     
    261262                        syscalls/syscalls.h           \
    262263                        kernel_config.h               \
    263                         $(HAL_ARCH)/core/hal_types.h
     264                        $(HAL_ARCH)/core/hal_kernel_types.h
    264265        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
    265266
     
    269270                        fs/%.h                        \
    270271                        kernel_config.h               \
    271                         $(HAL_ARCH)/core/hal_types.h
     272                        $(HAL_ARCH)/core/hal_kernel_types.h
    272273        $(CC) $(KERNEL_INCLUDE) $(CFLAGS) -c -o $@ $<
    273274
  • trunk/kernel/devices/dev_dma.c

    r437 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <chdev.h>
  • trunk/kernel/devices/dev_dma.h

    r437 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <spinlock.h>
    3030
  • trunk/kernel/devices/dev_fbf.c

    r440 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_gpt.h>
    2727#include <thread.h>
  • trunk/kernel/devices/dev_fbf.h

    r188 r457  
    2525#define _DEV_FBF_H
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828
    2929/****  Forward declarations  ****/
  • trunk/kernel/devices/dev_iob.c

    r422 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <remote_spinlock.h>
  • trunk/kernel/devices/dev_iob.h

    r346 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <spinlock.h>
    3030
  • trunk/kernel/devices/dev_ioc.c

    r440 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_gpt.h>
    2727#include <hal_drivers.h>
  • trunk/kernel/devices/dev_ioc.h

    r437 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929
    3030/****  Forward declarations  ****/
  • trunk/kernel/devices/dev_mmc.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <hal_drivers.h>
  • trunk/kernel/devices/dev_mmc.h

    r440 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <spinlock.h>
    3030
  • trunk/kernel/devices/dev_nic.c

    r438 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <printk.h>
  • trunk/kernel/devices/dev_nic.h

    r437 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929
    3030/*****************************************************************************************
  • trunk/kernel/devices/dev_pic.c

    r438 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <chdev.h>
     
    179179uint32_t cycle = (uint32_t)hal_get_cycles();
    180180if( DEBUG_DEV_PIC < cycle )
    181 printk("\n[DBG] %s : src_core[%x,%d] / dst_core[%x,%d] / cycle %d\n",
    182 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cxy, lid, cycle );
     181printk("\n[DBG] %s : thread %x in process %x / tgt_core[%x,%d] / cycle %d\n",
     182__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cxy, lid, cycle );
    183183#endif
    184184
  • trunk/kernel/devices/dev_pic.h

    r437 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929
    3030/*****************************************************************************************
  • trunk/kernel/devices/dev_txt.c

    r438 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <hal_remote.h>
  • trunk/kernel/devices/dev_txt.h

    r435 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <xlist.h>
    3030#include <remote_spinlock.h>
  • trunk/kernel/fs/devfs.c

    r438 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <hal_uspace.h>
     
    9999#endif
    100100
    101     // creates DEVFS "dev" inode in cluster IO
    102     error = vfs_add_child_in_parent( LOCAL_CLUSTER->io_cxy,
     101    // creates DEVFS "dev" inode in cluster 0
     102    error = vfs_add_child_in_parent( 0,                // cxy
    103103                                     INODE_TYPE_DIR,
    104104                                     FS_TYPE_DEVFS,
     
    115115#endif
    116116
    117     // create DEVFS "external" inode in cluster IO
    118     error = vfs_add_child_in_parent( LOCAL_CLUSTER->io_cxy,
     117    // create DEVFS "external" inode in cluster 0
     118    error = vfs_add_child_in_parent( 0,               // cxy
    119119                                     INODE_TYPE_DIR,
    120120                                     FS_TYPE_DEVFS,
  • trunk/kernel/fs/fatfs.c

    r440 r457  
    2323
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <printk.h>
  • trunk/kernel/fs/fatfs.h

    r407 r457  
    2626#define _FATFS_H_
    2727
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <rwlock.h>
    3030#include <vfs.h>
  • trunk/kernel/fs/ramfs.c

    r188 r457  
    2424
    2525
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727#include <hal_special.h>
    2828#include <printk.h>
  • trunk/kernel/fs/vfs.c

    r441 r457  
    2525
    2626#include <kernel_config.h>
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <hal_atomic.h>
    2929#include <hal_special.h>
  • trunk/kernel/fs/vfs.h

    r437 r457  
    2727
    2828#include <kernel_config.h>
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030#include <hal_atomic.h>
    3131#include <remote_rwlock.h>
  • trunk/kernel/kern/chdev.c

    r450 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <hal_remote.h>
     
    127127    xptr_t     server_xp;     // extended pointer on server thread
    128128    core_t   * core_ptr;      // local pointer on core running the server thread
    129     uint32_t   lid;           // core running the server thread local index
     129    uint32_t   server_lid;    // core running the server thread local index
    130130    xptr_t     lock_xp;       // extended pointer on lock protecting the chdev queue
    131     uint32_t   different;     // non zero if server thread core != client thread core
    132131    uint32_t   save_sr;       // for critical section
    133132
     
    154153
    155154    // get server core local index
    156     lid = hal_remote_lw( XPTR( chdev_cxy , &core_ptr->lid ) );
     155    server_lid = hal_remote_lw( XPTR( chdev_cxy , &core_ptr->lid ) );
    157156
    158157#if (DEBUG_CHDEV_CMD_RX || DEBUG_CHDEV_CMD_TX)
     
    210209#endif
    211210
     211#if (DEBUG_CHDEV_CMD_RX & 1)
     212if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
     213printk("\n[DBG] in %s : client thread %x blocked\n", __FUNCTION__, this );
     214#endif
     215
    212216    // unblock server thread if required
    213217    if( hal_remote_lw( blocked_xp ) & THREAD_BLOCKED_IDLE )
     
    216220#if (DEBUG_CHDEV_CMD_TX & 1)
    217221if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
    218 {
    219 printk("\n[DBG] in %s : server thread %x unblocked\n", __FUNCTION__, server_ptr );
    220 chdev_queue_display( chdev_xp );
    221 }
     222printk("\n[DBG] in %s : TX server thread %x unblocked\n", __FUNCTION__, server_ptr );
     223#endif
     224
     225#if (DEBUG_CHDEV_CMD_RX & 1)
     226if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
     227printk("\n[DBG] in %s : RX server thread %x unblocked\n", __FUNCTION__, server_ptr );
    222228#endif
    223229
     
    227233#if (DEBUG_CHDEV_CMD_TX & 1)
    228234if( (is_rx == 0)  && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
    229 {
    230235printk("\n[DBG] in %s : thread %x registered write request in chdev\n", __FUNCTION__, this );
    231 chdev_queue_display( chdev_xp );
    232 }
     236#endif
     237 
     238#if (DEBUG_CHDEV_CMD_RX & 1)
     239if( (is_rx)  && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
     240printk("\n[DBG] in %s : thread %x registered read request in chdev\n", __FUNCTION__, this );
    233241#endif
    234242 
    235243    // send IPI to core running the server thread when server != client
    236     different = (lid != this->core->lid) || (local_cxy != chdev_cxy);
    237     if( different )
    238     {
    239         dev_pic_send_ipi( chdev_cxy , lid );
    240    
     244    if( (server_lid != this->core->lid) || (local_cxy != chdev_cxy) )
     245    {
     246        dev_pic_send_ipi( chdev_cxy , server_lid );
     247
    241248#if (DEBUG_CHDEV_CMD_TX & 1)
    242249if( (is_rx == 0)  && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
    243 printk("\n[DBG] in %s : client thread %x sent IPI to server thread %x\n",
     250printk("\n[DBG] in %s : client thread %x sent IPI to TX server thread %x\n",
     251__FUNCTION__, this, server_ptr );
     252#endif
     253
     254#if (DEBUG_CHDEV_CMD_RX & 1)
     255if( (is_rx)  && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
     256printk("\n[DBG] in %s : client thread %x sent IPI to RX server thread %x\n",
    244257__FUNCTION__, this, server_ptr );
    245258#endif
  • trunk/kernel/kern/chdev.h

    r450 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <xlist.h>
    3030#include <remote_spinlock.h>
  • trunk/kernel/kern/cluster.c

    r456 r457  
    123123
    124124#if( DEBUG_CLUSTER_INIT & 1 )
    125 uint32_t cycle = (uint32_t)hal_get_cycles();
     125cycle = (uint32_t)hal_get_cycles();
    126126if( DEBUG_CLUSTER_INIT < cycle )
    127127printk("\n[DBG] %s : KHM initialized in cluster %x at cycle %d\n",
     
    133133
    134134#if( DEBUG_CLUSTER_INIT & 1 )
    135 uint32_t cycle = (uint32_t)hal_get_cycles();
     135cycle = (uint32_t)hal_get_cycles();
    136136if( DEBUG_CLUSTER_INIT < cycle )
    137137printk("\n[DBG] %s : KCM initialized in cluster %x at cycle %d\n",
  • trunk/kernel/kern/cluster.h

    r443 r457  
    2828
    2929#include <kernel_config.h>
    30 #include <hal_types.h>
     30#include <hal_kernel_types.h>
    3131#include <bits.h>
    3232#include <spinlock.h>
  • trunk/kernel/kern/core.c

    r443 r457  
    2424
    2525#include <kernel_config.h>
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727#include <hal_special.h>
    2828#include <errno.h>
  • trunk/kernel/kern/core.h

    r443 r457  
    2727
    2828#include <kernel_config.h>
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030#include <list.h>
    3131#include <rpc.h>
     
    6565}
    6666core_t;
    67 
    68 /****************************************************************************************
    69  * This macro returns a pointer on the calling core descriptor.
    70  ***************************************************************************************/
    71 
    72 #define CURRENT_CORE  (CURRENT_THREAD->core)
    7367
    7468/***************************************************************************************
  • trunk/kernel/kern/do_interrupt.c

    r248 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <kernel_config.h>
    2626#include <thread.h>
  • trunk/kernel/kern/do_interrupt.h

    r16 r457  
    2727#define _DO_INTERRUPT_H_
    2828
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030#include <thread.h>
    3131
  • trunk/kernel/kern/do_syscall.c

    r443 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_irqmask.h>
    2626#include <do_syscall.h>
     
    102102    sys_trace,              // 47
    103103    sys_fg,                 // 48
    104     sys_undefined,          // 49
     104    sys_is_fg,              // 49
    105105};
    106106
     
    160160        else if( index == SYS_TRACE          ) return "TRACE";            // 47
    161161        else if( index == SYS_FG             ) return "FG";               // 48
     162        else if( index == SYS_IS_FG          ) return "IS_FG";            // 49
    162163
    163164    else                                   return "undefined";   
  • trunk/kernel/kern/do_syscall.h

    r408 r457  
    2727#define _D0_SYSCALL_H_
    2828
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030#include <thread.h>
    3131
  • trunk/kernel/kern/dqdt.c

    r438 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <hal_atomic.h>
  • trunk/kernel/kern/dqdt.h

    r438 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <hal_atomic.h>
    3030
  • trunk/kernel/kern/kernel_init.c

    r443 r457  
    2525#include <kernel_config.h>
    2626#include <errno.h>
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <hal_special.h>
    2929#include <hal_context.h>
     
    186186           "    /_/        \\_\\ |______| |_|    |_|   \\_____/  |______/        |_|    |_|  |_|  \\_\\ |_|   |_|  \n"
    187187           "\n\n\t\t Advanced Locality Management Operating System / Multi Kernel Hybrid\n"
    188            "\n\n\t\t Version 0.0 / %d cluster(s) / %d core(s) per cluster / cycle %d\n\n",
    189            nclusters , ncores , hal_time_stamp() );
     188           "\n\n\t\t %s / %d cluster(s) / %d core(s) per cluster\n\n",
     189           CONFIG_ALMOS_VERSION , nclusters , ncores );
    190190}
    191191
     
    761761    reg_t        status;                    // running core status register
    762762
    763     cxy_t        io_cxy = info->io_cxy;
    764 
    765     assert( (io_cxy == ((info->x_size - 1)<<(info->y_width)) + (info->y_size - 1)) ,
    766     __FUNCTION__ , "illegal IO cluter identifier\n" );
    767 
    768763    /////////////////////////////////////////////////////////////////////////////////
    769764    // STEP 0 : Each core get its core identifier from boot_info, and makes
     
    796791    thread->remote_locks = 0;
    797792
    798     // CP0 in I/O cluster initialises TXT0 chdev descriptor
    799     if( (core_lid == 0) && (core_cxy == io_cxy) ) txt0_device_init( info );
    800 
    801     /////////////////////////////////////////////////////////////////////////////////
    802     if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
     793    // CP0 in cluster 0 initialises TXT0 chdev descriptor
     794    if( (core_lid == 0) && (core_cxy == 0) ) txt0_device_init( info );
     795
     796    /////////////////////////////////////////////////////////////////////////////////
     797    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ),
    803798                                        (info->x_size * info->y_size) );
    804799    barrier_wait( &local_barrier , info->cores_nr );
     
    838833
    839834    /////////////////////////////////////////////////////////////////////////////////
    840     if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
     835    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ),
    841836                                        (info->x_size * info->y_size) );
    842837    barrier_wait( &local_barrier , info->cores_nr );
     
    865860   
    866861    ////////////////////////////////////////////////////////////////////////////////
    867     if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
     862    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ),
    868863                                        (info->x_size * info->y_size) );
    869864    barrier_wait( &local_barrier , info->cores_nr );
     
    898893
    899894    /////////////////////////////////////////////////////////////////////////////////
    900     if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
     895    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ),
    901896                                        (info->x_size * info->y_size) );
    902897    barrier_wait( &local_barrier , info->cores_nr );
     
    926921
    927922    // all cores initialize the idle thread descriptor
    928     error = thread_idle_init( thread,
    929                               THREAD_IDLE,
    930                               &thread_idle_func,
    931                               NULL,
    932                               core_lid );
    933     if( error )
    934     {
    935         assert( false , __FUNCTION__ ,
    936         "core[%x][%d] cannot initialize idle thread", local_cxy , core_lid );
    937     }
     923    thread_idle_init( thread,
     924                      THREAD_IDLE,
     925                      &thread_idle_func,
     926                      NULL,
     927                      core_lid );
    938928
    939929    // all cores unblock idle thread, and register it in scheduler
     
    1008998
    1009999    /////////////////////////////////////////////////////////////////////////////////
    1010     if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
     1000    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ),
    10111001                                        (info->x_size * info->y_size) );
    10121002    barrier_wait( &local_barrier , info->cores_nr );
     
    10691059
    10701060    /////////////////////////////////////////////////////////////////////////////////
    1071     if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
     1061    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ),
    10721062                                        (info->x_size * info->y_size) );
    10731063    barrier_wait( &local_barrier , info->cores_nr );
     
    10761066#if DEBUG_KERNEL_INIT
    10771067if( (core_lid ==  0) & (local_cxy == 0) )
    1078 printk("\n[DBG] %s : exit barrier 5 : VFS_root = %l in cluster %x / cycle %d\n",
    1079 __FUNCTION__, vfs_root_inode_xp , io_cxy , (uint32_t)hal_get_cycles());
     1068printk("\n[DBG] %s : exit barrier 5 : VFS_root = %l in cluster 0 / cycle %d\n",
     1069__FUNCTION__, vfs_root_inode_xp , (uint32_t)hal_get_cycles());
    10801070#endif
    10811071
     
    10861076    /////////////////////////////////////////////////////////////////////////////////
    10871077
    1088     if( (core_lid ==  0) && (local_cxy == io_cxy) )
     1078    if( (core_lid ==  0) && (local_cxy == 0) )
    10891079    {
    10901080        // create "dev" and "external" directories.
     
    11041094
    11051095    /////////////////////////////////////////////////////////////////////////////////
    1106     if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
     1096    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ),
    11071097                                        (info->x_size * info->y_size) );
    11081098    barrier_wait( &local_barrier , info->cores_nr );
     
    11111101#if DEBUG_KERNEL_INIT
    11121102if( (core_lid ==  0) & (local_cxy == 0) )
    1113 printk("\n[DBG] %s : exit barrier 6 : dev_root = %l in cluster %x / cycle %d\n",
    1114 __FUNCTION__, devfs_dev_inode_xp , io_cxy , (uint32_t)hal_get_cycles() );
     1103printk("\n[DBG] %s : exit barrier 6 : dev_root = %l in cluster 0 / cycle %d\n",
     1104__FUNCTION__, devfs_dev_inode_xp , (uint32_t)hal_get_cycles() );
    11151105#endif
    11161106
     
    11251115    if( core_lid == 0 )
    11261116    {
    1127         // get extended pointer on "extend" field of VFS context for DEVFS in cluster IO
    1128         xptr_t  extend_xp = XPTR( io_cxy , &fs_context[FS_TYPE_DEVFS].extend );
    1129 
    1130         // get pointer on DEVFS context in cluster IO
     1117        // get extended pointer on "extend" field of VFS context for DEVFS in cluster 0
     1118        xptr_t  extend_xp = XPTR( 0 , &fs_context[FS_TYPE_DEVFS].extend );
     1119
     1120        // get pointer on DEVFS context in cluster 0
    11311121        devfs_ctx_t * devfs_ctx = hal_remote_lpt( extend_xp );
    11321122       
    1133         devfs_dev_inode_xp      = hal_remote_lwd( XPTR( io_cxy ,
    1134                                                         &devfs_ctx->dev_inode_xp ) );
    1135         devfs_external_inode_xp = hal_remote_lwd( XPTR( io_cxy ,
    1136                                                         &devfs_ctx->external_inode_xp ) );
     1123        devfs_dev_inode_xp      = hal_remote_lwd( XPTR( 0 , &devfs_ctx->dev_inode_xp ) );
     1124        devfs_external_inode_xp = hal_remote_lwd( XPTR( 0 , &devfs_ctx->external_inode_xp ) );
    11371125
    11381126        // populate DEVFS in all clusters
     
    11431131
    11441132    /////////////////////////////////////////////////////////////////////////////////
    1145     if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
     1133    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ),
    11461134                                        (info->x_size * info->y_size) );
    11471135    barrier_wait( &local_barrier , info->cores_nr );
     
    11581146    /////////////////////////////////////////////////////////////////////////////////
    11591147
    1160     if( (core_lid ==  0) && (local_cxy == 0) )
     1148    if( (core_lid == 0) && (local_cxy == 0) )
    11611149    {
    11621150
     
    11691157
    11701158    /////////////////////////////////////////////////////////////////////////////////
    1171     if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
     1159    if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ),
    11721160                                        (info->x_size * info->y_size) );
    11731161    barrier_wait( &local_barrier , info->cores_nr );
     
    11891177    /////////////////////////////////////////////////////////////////////////////////
    11901178   
    1191     if( (core_lid ==  0) && (local_cxy == io_cxy) )
     1179    if( (core_lid == 0) && (local_cxy == 0) )
    11921180    {
    11931181        print_banner( (info->x_size * info->y_size) , info->cores_nr );
  • trunk/kernel/kern/printk.c

    r446 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_irqmask.h>
    2626#include <hal_special.h>
  • trunk/kernel/kern/printk.h

    r437 r457  
    4141#define _PRINTK_H
    4242
    43 #include <hal_types.h>
     43#include <hal_kernel_types.h>
    4444#include <stdarg.h>
    4545
  • trunk/kernel/kern/process.c

    r450 r457  
    2525
    2626#include <kernel_config.h>
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <hal_remote.h>
    2929#include <hal_uspace.h>
     
    8989void process_reference_init( process_t * process,
    9090                             pid_t       pid,
    91                              xptr_t      parent_xp,
    92                              xptr_t      model_xp )
     91                             xptr_t      parent_xp )
    9392{
    9493    cxy_t       parent_cxy;
    9594    process_t * parent_ptr;
    96     cxy_t       model_cxy;
    97     process_t * model_ptr;
    9895    xptr_t      stdin_xp;
    9996    xptr_t      stdout_xp;
     
    110107    chdev_t *   chdev_ptr;
    111108    cxy_t       chdev_cxy;
    112     pid_t       model_pid;
    113109    pid_t       parent_pid;
    114 
    115     // get model process cluster and local pointer
    116     model_cxy = GET_CXY( model_xp );
    117     model_ptr = GET_PTR( model_xp );
    118110
    119111    // get parent process cluster and local pointer
     
    121113    parent_ptr = GET_PTR( parent_xp );
    122114
    123     // get model_pid and parent_pid
     115    // get parent_pid
    124116    parent_pid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
    125     model_pid  = hal_remote_lw( XPTR( model_cxy  , &model_ptr->pid ) );
    126117
    127118#if DEBUG_PROCESS_REFERENCE_INIT
    128119uint32_t cycle = (uint32_t)hal_get_cycles();
    129120if( DEBUG_PROCESS_REFERENCE_INIT )
    130 printk("\n[DBG] %s : thread %x enter / pid = %x / ppid = %x / model_pid = %x / cycle %d\n",
    131 __FUNCTION__ , CURRENT_THREAD , pid , parent_pid , model_pid , cycle );
     121printk("\n[DBG] %s : thread %x in process %x enter to initalialize process %x / cycle %d\n",
     122__FUNCTION__, CURRENT_THREAD->trdid, parent_pid , pid , cycle );
    132123#endif
    133124
     
    146137cycle = (uint32_t)hal_get_cycles();
    147138if( DEBUG_PROCESS_REFERENCE_INIT )
    148 printk("\n[DBG] %s : thread %x / vmm empty for process %x / cycle %d\n",
    149 __FUNCTION__ , CURRENT_THREAD , pid , cycle );
     139printk("\n[DBG] %s : thread %x in process %x / vmm empty for process %x / cycle %d\n",
     140__FUNCTION__, CURRENT_THREAD->trdid, parent_pid , cycle );
    150141#endif
    151142
     
    154145
    155146    // define the stdin/stdout/stderr pseudo files <=> select a TXT terminal.
    156     // - if INIT (pid == 1)         => link to kernel TXT[0]
    157     // - if KSH[i] (model_pid == 1) => allocate a free TXT[i]
    158     // - if USER process            => same terminal as model
    159 
    160     if( (pid == 1) || (model_pid == 1)) // INIT or KSH process
    161     {
    162         if (pid == 1 )  txt_id = 0;                    // INIT
    163         else            txt_id = process_txt_alloc();  // KSH[i]
    164 
    165         // attach process to TXT[txt_id]
     147    if( (pid == 1) || (parent_pid == 1)) // INIT or KSH process
     148    {
     149        // allocate a TXT channel
     150        if( pid == 1 )  txt_id = 0;                     // INIT
     151        else            txt_id = process_txt_alloc();   // KSH
     152
     153        // attach process to TXT
    166154        process_txt_attach( process , txt_id );
     155
     156#if (DEBUG_PROCESS_REFERENCE_INIT & 1)
     157cycle = (uint32_t)hal_get_cycles();
     158if( DEBUG_PROCESS_REFERENCE_INIT )
     159printk("\n[DBG] %s : thread %x in process %x / process %x attached to TXT%d / cycle %d\n",
     160__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, txt_id, cycle );
     161#endif
     162
     163
    167164
    168165        // build path to TXT_RX[i] and TXT_TX[i] chdevs
     
    184181cycle = (uint32_t)hal_get_cycles();
    185182if( DEBUG_PROCESS_REFERENCE_INIT )
    186 printk("\n[DBG] %s : thread %x / stdin open for process %x / cycle %d\n",
    187 __FUNCTION__ , CURRENT_THREAD , pid , cycle );
     183printk("\n[DBG] %s : thread %x in process %x / stdin open for process %x / cycle %d\n",
     184__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, cycle );
    188185#endif
    189186
     
    202199cycle = (uint32_t)hal_get_cycles();
    203200if( DEBUG_PROCESS_REFERENCE_INIT )
    204 printk("\n[DBG] %s : thread %x / stdout open for process %x / cycle %d\n",
    205 __FUNCTION__ , CURRENT_THREAD , pid , cycle );
     201printk("\n[DBG] %s : thread %x in process %x / stdout open for process %x / cycle %d\n",
     202__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, cycle );
    206203#endif
    207204
     
    220217cycle = (uint32_t)hal_get_cycles();
    221218if( DEBUG_PROCESS_REFERENCE_INIT )
    222 printk("\n[DBG] %s : thread %x / stderr open for process %x / cycle %d\n",
    223 __FUNCTION__ , CURRENT_THREAD , pid , cycle );
     219printk("\n[DBG] %s : thread %x in process %x / stderr open for process %x / cycle %d\n",
     220__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, cycle );
    224221#endif
    225222
     
    227224    else                                            // normal user process
    228225    {
    229         // get extended pointer on stdin pseudo file in model process
    230         file_xp = (xptr_t)hal_remote_lwd( XPTR( model_cxy , &model_ptr->fd_array.array[0] ) );
    231 
    232         // get extended pointer on model process TXT chdev
     226        // get extended pointer on stdin pseudo file in parent process
     227        file_xp = (xptr_t)hal_remote_lwd( XPTR( parent_cxy , &parent_ptr->fd_array.array[0] ) );
     228
     229        // get extended pointer on parent process TXT chdev
    233230        chdev_xp = chdev_from_file( file_xp );
    234231 
     
    243240        process_txt_attach( process , txt_id );
    244241
    245         // copy all open files from model process fd_array to this process
     242        // copy all open files from parent process fd_array to this process
    246243        process_fd_remote_copy( XPTR( local_cxy , &process->fd_array ),
    247                                 XPTR( model_cxy , &model_ptr->fd_array ) );
     244                                XPTR( parent_cxy , &parent_ptr->fd_array ) );
    248245    }
    249246
    250247    // initialize specific inodes root and cwd
    251     process->vfs_root_xp = (xptr_t)hal_remote_lwd( XPTR( model_cxy,
    252                                                          &model_ptr->vfs_root_xp ) );
    253     process->vfs_cwd_xp  = (xptr_t)hal_remote_lwd( XPTR( model_cxy,
    254                                                          &model_ptr->vfs_cwd_xp ) );
     248    process->vfs_root_xp = (xptr_t)hal_remote_lwd( XPTR( parent_cxy,
     249                                                         &parent_ptr->vfs_root_xp ) );
     250    process->vfs_cwd_xp  = (xptr_t)hal_remote_lwd( XPTR( parent_cxy,
     251                                                         &parent_ptr->vfs_cwd_xp ) );
    255252    vfs_inode_remote_up( process->vfs_root_xp );
    256253    vfs_inode_remote_up( process->vfs_cwd_xp );
     
    469466////////////////////////////////////////
    470467void process_sigaction( pid_t       pid,
    471                         uint32_t    action_type )
     468                        uint32_t    type )
    472469{
    473470    cxy_t              owner_cxy;         // owner cluster identifier
     
    479476    xptr_t             process_xp;        // extended pointer on process copy
    480477    cxy_t              process_cxy;       // process copy cluster identifier
     478    process_t        * process_ptr;       // local pointer on process copy
    481479    reg_t              save_sr;           // for critical section
    482480    rpc_desc_t         rpc;               // shared RPC descriptor
    483 
    484     thread_t * client = CURRENT_THREAD;
     481    thread_t         * client;            // pointer on client thread
     482    xptr_t             client_xp;         // extended pointer on client thread
     483    process_t        * local;             // pointer on process copy in local cluster
     484    uint32_t           remote_nr;         // number of remote process copies
     485
     486    client    = CURRENT_THREAD;
     487    client_xp = XPTR( local_cxy , client );
     488    local     = NULL;
     489    remote_nr = 0;
    485490
    486491#if DEBUG_PROCESS_SIGACTION
    487492uint32_t cycle = (uint32_t)hal_get_cycles();
    488493if( DEBUG_PROCESS_SIGACTION < cycle )
    489 printk("\n[DBG] %s : thread %x enter to %s process %x / cycle %d\n",
    490 __FUNCTION__ , client, process_action_str( action_type ) , pid , cycle );
     494printk("\n[DBG] %s : thread %x in process %x enter to %s process %x / cycle %d\n",
     495__FUNCTION__ , client->trdid, client->process->pid,
     496process_action_str( type ) , pid , cycle );
    491497#endif
    492498
     
    503509
    504510    // check action type
    505     assert( ((action_type == DELETE_ALL_THREADS ) ||
    506              (action_type == BLOCK_ALL_THREADS )  ||
    507              (action_type == UNBLOCK_ALL_THREADS )), __FUNCTION__ , "illegal action type" );
     511    assert( ((type == DELETE_ALL_THREADS ) ||
     512             (type == BLOCK_ALL_THREADS )  ||
     513             (type == UNBLOCK_ALL_THREADS )), __FUNCTION__ , "illegal action type" );
    508514             
    509     // allocate a - shared - RPC descriptor in client thread stack
    510     // it can be shared because all parallel, non-blocking, server threads
    511     // use the same input arguments, and use the shared RPC response field
    512 
    513     // the client thread makes the following sequence:
    514     // 1. mask interrupts
    515     // 2. block itself
    516     // 3. send RPC requests to all copies
    517     // 4. unmask interrupts
    518     // 5. deschedule
     515
     516    // The client thread send parallel RPCs to all remote clusters containing
     517    // target process copies, wait all responses, and then handles directly the
     518    // threads in local cluster, when required.
     519    // The client thread allocates a - shared - RPC descriptor in the stack,
     520    // because all parallel, non-blocking, server threads use the same input
     521    // arguments, and use the shared RPC response field
    519522
    520523    // mask IRQs
    521524    hal_disable_irq( &save_sr);
    522525
    523     // client register blocking condition for itself
    524     thread_block( XPTR( local_cxy , client ) , THREAD_BLOCKED_RPC );
     526    // client thread blocks itself
     527    thread_block( client_xp , THREAD_BLOCKED_RPC );
    525528
    526529    // take the lock protecting the copies
     
    533536    rpc.thread    = client;
    534537    rpc.lid       = client->core->lid;
    535     rpc.args[0]   = action_type;
     538    rpc.args[0]   = type;
    536539    rpc.args[1]   = pid;
    537540
    538     // send RPCs to all clusters containing process copiess
     541    // scan list of process copies
     542    // to send RPCs to remote copies
    539543    XLIST_FOREACH( root_xp , iter_xp )
    540544    {
    541         // atomically increment responses counter
    542         hal_atomic_add( (void *)&rpc.responses , 1 );
    543 
     545        // get extended pointers and cluster on process
    544546        process_xp  = XLIST_ELEMENT( iter_xp , process_t , copies_list );
    545547        process_cxy = GET_CXY( process_xp );
     548        process_ptr = GET_PTR( process_xp );
     549
     550        if( process_cxy == local_cxy )    // process is local
     551        {
     552            local = process_ptr;
     553        }
     554        else                              // process is remote
     555        {
     556            // update number of remote process copies
     557            remote_nr++;
     558
     559            // atomically increment responses counter
     560            hal_atomic_add( (void *)&rpc.responses , 1 );
    546561
    547562#if DEBUG_PROCESS_SIGACTION
    548563if( DEBUG_PROCESS_SIGACTION < cycle )
    549 printk("\n[DBG] %s : send RPC to %s process %x in cluster %x\n",
    550 __FUNCTION__ , process_action_str( action_type ) , pid , process_cxy );
    551 #endif
    552         // call RPC in target cluster
    553         rpc_process_sigaction_client( process_cxy , &rpc );
    554     }
    555    
     564printk("\n[DBG] %s : thread %x in process %x handles remote process %x in cluster %x\n",
     565__FUNCTION__, client->trdid, client->process->pid, pid , process_cxy );
     566#endif
     567            // call RPC in target cluster
     568            rpc_process_sigaction_client( process_cxy , &rpc );
     569        }
     570    }  // end list of copies
     571
    556572    // release the lock protecting process copies
    557573    remote_spinlock_unlock( lock_xp );
     
    560576    hal_restore_irq( save_sr);
    561577
    562     // client thread deschedule : will be unblocked by the last RPC server thread
    563     sched_yield("blocked on rpc_process_sigaction");
     578    // - if there is remote process copies, the client thread deschedules,
     579    //   (it will be unblocked by the last RPC server thread).
     580    // - if there is no remote copies, the client thread unblock itself.
     581    if( remote_nr )
     582    {
     583        sched_yield("blocked on rpc_process_sigaction");
     584    }
     585    else
     586    {
     587        thread_unblock( client_xp , THREAD_BLOCKED_RPC );
     588    }
     589
     590    // handle the local process copy if required
     591    if( local != NULL )
     592    {
     593
     594#if DEBUG_PROCESS_SIGACTION
     595if( DEBUG_PROCESS_SIGACTION < cycle )
     596printk("\n[DBG] %s : thread %x in process %x handles local process %x in cluster %x\n",
     597__FUNCTION__, client->trdid, client->process->pid, pid , local_cxy );
     598#endif
     599        if     (type == DELETE_ALL_THREADS  ) process_delete_threads ( local , client_xp );
     600        else if(type == BLOCK_ALL_THREADS   ) process_block_threads  ( local , client_xp );
     601        else if(type == UNBLOCK_ALL_THREADS ) process_unblock_threads( local );
     602    }
    564603
    565604#if DEBUG_PROCESS_SIGACTION
    566605cycle = (uint32_t)hal_get_cycles();
    567606if( DEBUG_PROCESS_SIGACTION < cycle )
    568 printk("\n[DBG] %s : thread %x exit after %s process %x in cluster %x / cycle %d\n",
    569 __FUNCTION__ , client, process_action_str( action_type ) , pid , local_cxy , cycle );
     607printk("\n[DBG] %s : thread %x in process %x exit after %s process %x / cycle %d\n",
     608__FUNCTION__, client->trdid, client->process->pid,
     609process_action_str( type ), pid, cycle );
    570610#endif
    571611
     
    11001140uint32_t cycle = (uint32_t)hal_get_cycles();
    11011141if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1102 printk("\n[DBG] %s : thread %x enter for process %x / cluster %x / cycle %d\n",
    1103 __FUNCTION__, CURRENT_THREAD, parent_pid, local_cxy, cycle );
     1142printk("\n[DBG] %s : thread %x in process %x enter / cluster %x / cycle %d\n",
     1143__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, local_cxy, cycle );
    11041144#endif
    11051145
     
    11231163    }
    11241164
     1165#if DEBUG_PROCESS_MAKE_FORK
     1166cycle = (uint32_t)hal_get_cycles();
     1167if( DEBUG_PROCESS_MAKE_FORK < cycle )
     1168printk("\n[DBG] %s : thread %x in process %x allocated process %x / cycle %d\n",
     1169__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, new_pid, cycle );
     1170#endif
     1171
    11251172    // initializes child process descriptor from parent process descriptor
    11261173    process_reference_init( process,
    11271174                            new_pid,
    1128                             parent_process_xp,
    11291175                            parent_process_xp );
    11301176
     
    11321178cycle = (uint32_t)hal_get_cycles();
    11331179if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1134 printk("\n[DBG] %s : thread %x created child_process %x / child_pid %x / cycle %d\n",
    1135 __FUNCTION__, CURRENT_THREAD, process, new_pid, cycle );
    1136 #endif
     1180printk("\n[DBG] %s : thread %x in process %x initialized child_process %x / cycle %d\n",
     1181__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, new_pid, cycle );
     1182#endif
     1183
     1184    // give TXT ownership to child process
     1185    process_txt_set_ownership( XPTR( local_cxy , process ) );
    11371186
    11381187    // copy VMM from parent descriptor to child descriptor
     
    11511200cycle = (uint32_t)hal_get_cycles();
    11521201if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1153 printk("\n[DBG] %s : thread %x copied VMM from parent %x to child %x / cycle %d\n",
    1154 __FUNCTION__ , CURRENT_THREAD , parent_pid, new_pid, cycle );
    1155 #endif
     1202printk("\n[DBG] %s : thread %x in process %x copied VMM from parent %x to child %x / cycle %d\n",
     1203__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
     1204parent_pid, new_pid, cycle );
     1205#endif
     1206
     1207    // parent process gives TXT ownership to child process if required
     1208    if( process_txt_is_owner(parent_process_xp) )
     1209    {
     1210        process_txt_set_ownership( XPTR( local_cxy , process ) );
     1211
     1212#if( DEBUG_PROCESS_MAKE_FORK & 1 )
     1213cycle = (uint32_t)hal_get_cycles();
     1214if( DEBUG_PROCESS_MAKE_EXEC < cycle )
     1215printk("\n[DBG] %s : thread %x in process %x gives TXT from parent %x to child %x / cycle %d\n",
     1216__FUNCTION__ , CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
     1217parent_pid, new_pid, cycle );
     1218#endif
     1219
     1220    }
    11561221
    11571222    // update extended pointer on .elf file
     
    11781243cycle = (uint32_t)hal_get_cycles();
    11791244if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1180 printk("\n[DBG] %s : thread %x created child thread %x on core[%x,%d] / cycle %d\n",
    1181 __FUNCTION__ , CURRENT_THREAD, thread, local_cxy, thread->core->lid, cycle );
     1245printk("\n[DBG] %s : thread %x in process %x created main thread %x on core[%x,%d] / cycle %d\n",
     1246__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
     1247thread, local_cxy, thread->core->lid, cycle );
    11821248#endif
    11831249
     
    12001266cycle = (uint32_t)hal_get_cycles();
    12011267if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1202 printk("\n[DBG] %s : thread %x set COW in parent and child / cycle %d\n",
    1203 __FUNCTION__ , CURRENT_THREAD, cycle );
     1268printk("\n[DBG] %s : thread %x in process %x set COW in parent and child / cycle %d\n",
     1269__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cycle );
    12041270#endif
    12051271
     
    12221288cycle = (uint32_t)hal_get_cycles();
    12231289if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1224 printk("\n[DBG] %s : thread %x exit / cycle %d\n",
    1225 __FUNCTION__, CURRENT_THREAD, cycle );
     1290printk("\n[DBG] %s : thread %x in process %x exit / created process %x / cycle %d\n",
     1291__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, new_pid, cycle );
    12261292#endif
    12271293
     
    12291295
    12301296}   // end process_make_fork()
    1231 
    12321297
    12331298/////////////////////////////////////////////////////
    12341299error_t process_make_exec( exec_info_t  * exec_info )
    12351300{
    1236     char           * path;                    // pathname to .elf file
    1237     pid_t            pid;                     // old_process PID, given to new_process
    1238     pid_t            temp_pid;                // temporary PID / given to old_process
    1239     process_t      * old_process;             // local pointer on old process
    1240     thread_t       * old_thread;              // local pointer on old thread
    1241     process_t      * new_process;             // local pointer on new process
    1242     thread_t       * new_thread;              // local pointer on new thread
    1243     xptr_t           parent_xp;               // extended pointer on parent process
    1244     process_t      * parent_ptr;              // local pointer on parent process
    1245     cxy_t            parent_cxy;              // parent process cluster identifier
    1246     xptr_t           children_lock_xp;        // extended pointer on children lock in parent
    1247     xptr_t           children_root_xp;        // extended pointer on children root in parent
    1248     xptr_t           children_nr_xp;          // extended pointer on children number in parent
    1249     thread_t       * parent_main_ptr;         // local pointer on parent main thread
    1250     xptr_t           parent_main_xp;          // extended pointer on parent main thread
    1251     pthread_attr_t   attr;                    // new thread attributes
    1252     lid_t            lid;                     // selected core local index
     1301    thread_t       * thread;                  // local pointer on this thread
     1302    process_t      * process;                 // local pointer on this process
     1303    pid_t            pid;                     // this process identifier
    12531304        error_t          error;                   // value returned by called functions
    1254    
    1255     // get old_thread, old_process & PID
    1256     old_thread  = CURRENT_THREAD;
    1257     old_process = old_thread->process;
    1258     pid         = old_process->pid;
    1259 
    1260         // get .elf pathname from exec_info
    1261         path = exec_info->path;
    1262 
    1263     // this function must be executed by a thread running in owner cluster
    1264     assert( (CXY_FROM_PID( pid ) == local_cxy), __FUNCTION__,
    1265     "local_cluster must be owner_cluster\n" );
    1266 
    1267     assert( (LTID_FROM_TRDID( old_thread->trdid ) == 0) , __FUNCTION__,
    1268     "must be called by the main thread\n" );
    1269  
     1305    char           * path;                    // path to .elf file
     1306    xptr_t           file_xp;                 // extended pointer on .elf file descriptor
     1307    uint32_t         file_id;                 // file index in fd_array
     1308    uint32_t         args_nr;                 // number of main thread arguments
     1309    char          ** args_pointers;           // array of pointers on main thread arguments
     1310
     1311    // get thread, process & PID
     1312    thread  = CURRENT_THREAD;
     1313    process = thread->process;
     1314    pid     = process->pid;
     1315
     1316        // get relevant infos from exec_info
     1317        path          = exec_info->path;
     1318    args_nr       = exec_info->args_nr;
     1319    args_pointers = exec_info->args_pointers;
     1320
    12701321#if DEBUG_PROCESS_MAKE_EXEC
    12711322uint32_t cycle = (uint32_t)hal_get_cycles();
    12721323if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    12731324printk("\n[DBG] %s : thread %x in process %x enters / path %s / cycle %d\n",
    1274 __FUNCTION__, old_thread->trdid, pid, path, cycle );
    1275 #endif
    1276 
    1277     // get parent process pointers
    1278     parent_xp   = old_process->parent_xp;
    1279     parent_cxy  = GET_CXY( parent_xp );
    1280     parent_ptr  = GET_PTR( parent_xp );
    1281    
     1325__FUNCTION__, thread->trdid, pid, path, cycle );
     1326#endif
     1327
     1328    // open the file identified by <path>
     1329    file_xp = XPTR_NULL;
     1330    file_id = -1;
     1331        error   = vfs_open( process,
     1332                            path,
     1333                            O_RDONLY,
     1334                            0,
     1335                            &file_xp,
     1336                            &file_id );
     1337        if( error )
     1338        {
     1339                printk("\n[ERROR] in %s : failed to open file <%s>\n", __FUNCTION__ , path );
     1340                return -1;
     1341        }
     1342
    12821343#if (DEBUG_PROCESS_MAKE_EXEC & 1)
    12831344if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1284 printk("\n[DBG] %s : thread %x in process %x get parent process %x in cluster %x\n",
    1285 __FUNCTION__, old_thread->trdid, pid, parent_ptr, parent_cxy );
    1286 #endif
    1287 
    1288     // get extended pointers on parent children_root, children_lock and children_nr
    1289     children_root_xp = XPTR( parent_cxy , &parent_ptr->children_root );
    1290     children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
    1291     children_nr_xp   = XPTR( parent_cxy , &parent_ptr->children_nr   );
    1292 
    1293     // get pointers on the parent process main thread
    1294     parent_main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) );
    1295     parent_main_xp  = XPTR( parent_cxy , parent_main_ptr );
    1296 
    1297      // allocate memory for new_process descriptor
    1298     new_process = process_alloc();
    1299 
    1300     if( new_process == NULL )
    1301     {
    1302         printk("\n[ERROR] in %s : cannot allocate process for %s\n", __FUNCTION__ , path );
     1345printk("\n[DBG] %s : open file <%s>\n", __FUNCTION__, path );
     1346#endif
     1347
     1348    // delete all threads other than this main thread in all clusters
     1349    process_sigaction( pid , DELETE_ALL_THREADS );
     1350
     1351    // reset local process VMM
     1352    vmm_destroy( process );
     1353
     1354#if( DEBUG_PROCESS_MAKE_EXEC & 1 )
     1355cycle = (uint32_t)hal_get_cycles();
     1356if( DEBUG_PROCESS_MAKE_EXEC < cycle )
     1357printk("\n[DBG] %s : thread %x in process %x / reset VMM / cycle %d\n",
     1358__FUNCTION__, thread->trdid, pid, cycle );
     1359#endif
     1360
     1361    // re-initialize the VMM (kentry/args/envs vsegs registration)
     1362    error = vmm_init( process );
     1363    if( error )
     1364    {
     1365        printk("\n[ERROR] in %s : cannot initialise VMM for %s\n", __FUNCTION__ , path );
     1366        vfs_close( file_xp , file_id );
     1367        // FIXME restore old process VMM
    13031368        return -1;
    13041369    }
    1305 
    1306     // get a temporary PID for old_process
    1307     error = cluster_pid_alloc( old_process , &temp_pid );
    1308     if( error )
    1309     {
    1310         printk("\n[ERROR] in %s : cannot get PID in cluster %x\n",
    1311         __FUNCTION__ , local_cxy );
    1312         process_free( new_process );
    1313         return -1;
    1314     }
    1315 
    1316     // set temporary PID to old_process
    1317     old_process->pid = temp_pid;
    1318 
    1319     // initialize new process descriptor
    1320     process_reference_init( new_process,
    1321                             pid,
    1322                             parent_xp,                          // parent_process_xp
    1323                             XPTR(local_cxy , old_process) );    // model_process
    1324 
    1325     // give TXT ownership to new_process
    1326     process_txt_set_ownership( XPTR( local_cxy , new_process) );
    1327 
     1370   
    13281371#if( DEBUG_PROCESS_MAKE_EXEC & 1 )
    13291372cycle = (uint32_t)hal_get_cycles();
    13301373if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1331 printk("\n[DBG] %s : thread %x in process %x created new process %x\n",
    1332 __FUNCTION__ , old_thread->trdid, pid, new_process );
    1333 #endif
    1334 
    1335     // register code & data vsegs as well as entry-point in new process VMM,
     1374printk("\n[DBG] %s : thread %x in process %x / kentry/args/envs vsegs registered / cycle %d\n",
     1375__FUNCTION__, thread->trdid, pid, cycle );
     1376#endif
     1377
     1378    // register code & data vsegs as well as entry-point in process VMM,
    13361379    // and register extended pointer on .elf file in process descriptor
    1337         error = elf_load_process( path , new_process );
    1338 
     1380        error = elf_load_process( file_xp , process );
    13391381    if( error )
    13401382        {
    13411383                printk("\n[ERROR] in %s : failed to access <%s>\n", __FUNCTION__ , path );
    1342         process_txt_set_ownership( XPTR( local_cxy , old_process) );
    1343         process_txt_detach( XPTR( local_cxy , new_process) );
    1344         process_destroy( new_process );
    1345         old_process->pid = pid;
     1384        vfs_close( file_xp , file_id );
     1385        // FIXME restore old process VMM
    13461386        return -1;
    13471387        }
     
    13501390cycle = (uint32_t)hal_get_cycles();
    13511391if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1352 printk("\n[DBG] %s : thread %x registered code/data vsegs in new process %x / cycle %d\n",
    1353 __FUNCTION__, old_thread , new_process->pid , cycle );
    1354 #endif
    1355 
    1356     // select a core in local cluster to execute the main thread
    1357     lid  = cluster_select_local_core();
    1358 
    1359     // initialize pthread attributes for main thread
    1360     attr.attributes = PT_ATTR_DETACH | PT_ATTR_CLUSTER_DEFINED | PT_ATTR_CORE_DEFINED;
    1361     attr.cxy        = local_cxy;
    1362     attr.lid        = lid;
    1363 
    1364     // create and initialize main thread in local cluster
    1365         error = thread_user_create( pid,
    1366                                 (void *)new_process->vmm.entry_point,
    1367                                 exec_info->args_pointers,
    1368                                 &attr,
    1369                                 &new_thread );
    1370         if( error )
    1371         {
    1372                 printk("\n[ERROR] in %s : cannot create thread for %s\n", __FUNCTION__ , path );
    1373         process_txt_set_ownership( XPTR( local_cxy , old_process) );
    1374         process_txt_detach( XPTR( local_cxy , new_process) );
    1375         process_destroy( new_process );
    1376         old_process->pid = pid;
     1392printk("\n[DBG] %s : thread %x in process %x / code/data vsegs registered / cycle %d\n",
     1393__FUNCTION__, thread->trdid, pid, cycle );
     1394#endif
     1395
     1396    // update the existing main thread descriptor... and jump to user code
     1397    error = thread_user_exec( (void *)process->vmm.entry_point,
     1398                              args_nr,
     1399                              args_pointers );
     1400    if( error )
     1401    {
     1402        printk("\n[ERROR] in %s : cannot reset main thread for %s\n", __FUNCTION__ , path );
     1403        vfs_close( file_xp , file_id );
     1404        // FIXME restore old process VMM
    13771405        return -1;
    1378         }
    1379 
    1380     // check main thread LTID
    1381     assert( (LTID_FROM_TRDID(new_thread->trdid) == 0) , __FUNCTION__ ,
    1382     "main thread must have LTID == 0\n" );
    1383 
    1384 #if( DEBUG_PROCESS_MAKE_EXEC & 1 )
    1385 cycle = (uint32_t)hal_get_cycles();
    1386 if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1387 printk("\n[DBG] %s : thread %x created new_process main thread %x / cycle %d\n",
    1388 __FUNCTION__ , old_thread , new_thread , cycle );
    1389 #endif
    1390 
    1391     // register new_process in parent children list
    1392     remote_spinlock_lock( children_lock_xp );
    1393         xlist_add_last( children_root_xp , XPTR( local_cxy , &new_process->children_list ) );
    1394         hal_remote_atomic_add( children_nr_xp , 1 );
    1395     remote_spinlock_unlock( children_lock_xp );
    1396 
    1397     // activate new thread
    1398         thread_unblock( XPTR( local_cxy , new_thread ) , THREAD_BLOCKED_GLOBAL );
    1399 
    1400     // detach old_process from TXT
    1401     process_txt_detach( XPTR( local_cxy , old_process ) );
    1402 
    1403     // block old_thread
    1404     thread_block( XPTR( local_cxy , old_thread ) , THREAD_BLOCKED_GLOBAL );
    1405 
    1406     // atomically update old_process termination state
    1407     hal_atomic_or( &old_process->term_state , PROCESS_TERM_EXIT );
    1408 
    1409     // take the children lock and unblock the parent process main thread
    1410     remote_spinlock_lock( children_lock_xp );
    1411     thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
    1412     remote_spinlock_unlock( children_lock_xp );
    1413 
    1414     hal_fence();
    1415 
    1416 #if DEBUG_PROCESS_MAKE_EXEC
    1417 cycle = (uint32_t)hal_get_cycles();
    1418 if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1419 printk("\n[DBG] %s : old thread %x blocked for delete / new thread %x activated / cycle %d\n",
    1420 __FUNCTION__ , old_thread , new_thread , cycle );
    1421 #endif
    1422    
     1406    }
     1407
     1408    assert( false, __FUNCTION__, "we should not execute this code");
     1409 
    14231410        return 0;
    14241411
    14251412}  // end process_make_exec()
     1413
    14261414
    14271415///////////////////////////////////////////////
     
    14741462    pthread_attr_t   attr;          // main thread attributes
    14751463    lid_t            lid;           // selected core local index for main thread
     1464    xptr_t           file_xp;       // extended pointer on .elf file descriptor
     1465    uint32_t         file_id;       // file index in fd_array
    14761466    error_t          error;
    14771467
     
    14791469uint32_t cycle = (uint32_t)hal_get_cycles();
    14801470if( DEBUG_PROCESS_INIT_CREATE < cycle )
    1481 printk("\n[DBG] %s : thread %x enter / cycle %d\n", __FUNCTION__, CURRENT_THREAD, cycle );
     1471printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n",
     1472__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cycle );
    14821473#endif
    14831474
    14841475    // allocates memory for process descriptor from local cluster
    14851476        process = process_alloc();
    1486         if( process == NULL )
    1487     {
    1488                 printk("\n[PANIC] in %s : no memory for process descriptor in cluster %x\n",
    1489                 __FUNCTION__, local_cxy  );
    1490     }
     1477       
     1478    assert( (process != NULL), __FUNCTION__,
     1479    "no memory for process descriptor in cluster %x\n", local_cxy  );
    14911480
    14921481    // get PID from local cluster
    14931482    error = cluster_pid_alloc( process , &pid );
    1494     if( error )
    1495     {
    1496                 printk("\n[PANIC] in %s : cannot allocate PID in cluster %x\n",
    1497                 __FUNCTION__, local_cxy );
    1498         process_free( process );
    1499     }
    1500 
    1501     // check allocated PID
    1502     assert( (pid == 1) , __FUNCTION__ , "process INIT must be first process in cluster 0\n" );
     1483
     1484    assert( (error == 0), __FUNCTION__,
     1485    "cannot allocate PID in cluster %x\n", local_cxy );
     1486
     1487    assert( (pid == 1) , __FUNCTION__,
     1488    "process INIT must be first process in cluster 0\n" );
    15031489
    15041490    // initialize process descriptor / parent is local process_zero
    15051491    process_reference_init( process,
    15061492                            pid,
    1507                             XPTR( local_cxy , &process_zero ),     // parent
    1508                             XPTR( local_cxy , &process_zero ) );   // model
     1493                            XPTR( local_cxy , &process_zero ) ); 
     1494
     1495    // open the file identified by CONFIG_PROCESS_INIT_PATH
     1496    file_xp = XPTR_NULL;
     1497    file_id = -1;
     1498        error   = vfs_open( process,
     1499                            CONFIG_PROCESS_INIT_PATH,
     1500                            O_RDONLY,
     1501                            0,
     1502                            &file_xp,
     1503                            &file_id );
     1504
     1505        assert( (error == 0), __FUNCTION__,
     1506    "failed to open file <%s>\n", CONFIG_PROCESS_INIT_PATH );
    15091507
    15101508    // register "code" and "data" vsegs as well as entry-point
    15111509    // in process VMM, using information contained in the elf file.
    1512         if( elf_load_process( CONFIG_PROCESS_INIT_PATH , process ) )
    1513         {
    1514                 printk("\n[PANIC] in %s : cannot access .elf file / path = %s\n",
    1515                 __FUNCTION__, CONFIG_PROCESS_INIT_PATH );
    1516         process_destroy( process );
    1517         }
     1510        error = elf_load_process( file_xp , process );
     1511
     1512        assert( (error == 0), __FUNCTION__,
     1513    "cannot access .elf file <%s>\n", CONFIG_PROCESS_INIT_PATH );
    15181514
    15191515    // get extended pointers on process_zero children_root, children_lock
     
    15411537                                &attr,
    15421538                                &thread );
    1543         if( error )
    1544         {
    1545                 printk("\n[PANIC] in %s : cannot create main thread / path = %s\n",
    1546                 __FUNCTION__, CONFIG_PROCESS_INIT_PATH );
    1547         process_destroy( process );
    1548         }
    1549 
    1550     // check main thread index
    1551     assert( (thread->trdid == 0) , __FUNCTION__ , "main thread must have index 0\n" );
     1539
     1540        assert( (error == 0), __FUNCTION__,
     1541    "cannot create main thread for <%s>\n", CONFIG_PROCESS_INIT_PATH );
     1542
     1543    assert( (thread->trdid == 0), __FUNCTION__,
     1544    "main thread must have index 0 for <%s>\n", CONFIG_PROCESS_INIT_PATH );
    15521545
    15531546    // activate thread
     
    15591552cycle = (uint32_t)hal_get_cycles();
    15601553if( DEBUG_PROCESS_INIT_CREATE < cycle )
    1561 printk("\n[DBG] %s : thread %x exit / cycle %d\n", __FUNCTION__, CURRENT_THREAD, cycle );
     1554printk("\n[DBG] %s : thread %x in process %x exit / cycle %d\n",
     1555__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cycle );
    15621556#endif
    15631557
     
    17021696    xptr_t      lock_xp;      // extended pointer on list lock in chdev
    17031697
    1704 #if DEBUG_PROCESS_TXT
    1705 uint32_t cycle = (uint32_t)hal_get_cycles();
    1706 if( DEBUG_PROCESS_TXT < cycle )
    1707 printk("\n[DBG] %s : thread %x enter for process %x / txt_id = %d  / cycle %d\n",
    1708 __FUNCTION__, CURRENT_THREAD, process->pid, txt_id, cycle );
    1709 #endif
    1710 
    17111698    // check process is in owner cluster
    17121699    assert( (CXY_FROM_PID( process->pid ) == local_cxy) , __FUNCTION__ ,
     
    17321719
    17331720#if DEBUG_PROCESS_TXT
    1734 cycle = (uint32_t)hal_get_cycles();
     1721uint32_t cycle = (uint32_t)hal_get_cycles();
    17351722if( DEBUG_PROCESS_TXT < cycle )
    1736 printk("\n[DBG] %s : thread %x exit for process %x / txt_id = %d / cycle %d\n",
    1737 __FUNCTION__, CURRENT_THREAD, process->pid, txt_id , cycle );
     1723printk("\n[DBG] %s : thread %x in process %x attached process %x to TXT %d / cycle %d\n",
     1724__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
     1725process->pid, txt_id , cycle );
    17381726#endif
    17391727
     
    17551743    process_cxy = GET_CXY( process_xp );
    17561744    process_ptr = GET_PTR( process_xp );
     1745
     1746    // check process descriptor in owner cluster
    17571747    process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
    1758 
    1759     // check process descriptor in owner cluster
    17601748    assert( (CXY_FROM_PID( process_pid ) == process_cxy ) , __FUNCTION__ ,
    17611749    "process descriptor not in owner cluster" );
    1762 
    1763 #if DEBUG_PROCESS_TXT
    1764 uint32_t cycle = (uint32_t)hal_get_cycles();
    1765 if( DEBUG_PROCESS_TXT < cycle )
    1766 printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n",
    1767 __FUNCTION__, CURRENT_THREAD, process_pid, cycle );
    1768 #endif
    17691750
    17701751    // release TXT ownership (does nothing if not TXT owner)
     
    17881769
    17891770#if DEBUG_PROCESS_TXT
    1790 cycle  = (uint32_t)hal_get_cycles();
     1771uint32_t cycle  = (uint32_t)hal_get_cycles();
    17911772uint32_t txt_id = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->channel ) );
    17921773if( DEBUG_PROCESS_TXT < cycle )
    1793 printk("\n[DBG] %s : thread %x exit / process %x detached from TXT %d / cycle %d\n",
    1794 __FUNCTION__, CURRENT_THREAD, process_pid, txt_id, cycle );
     1774printk("\n[DBG] %s : thread %x in process %x detached process %x from TXT %d / cycle %d\n",
     1775__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
     1776process_pid, txt_id, cycle );
    17951777#endif
    17961778
     
    18111793    process_cxy = GET_CXY( process_xp );
    18121794    process_ptr = GET_PTR( process_xp );
    1813 
    1814     // get process PID
    18151795    process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
    18161796
     
    18181798    assert( (process_cxy == CXY_FROM_PID( process_pid )) , __FUNCTION__,
    18191799    "process descriptor not in owner cluster\n" );
    1820 
    1821 #if DEBUG_PROCESS_TXT
    1822 uint32_t cycle = (uint32_t)hal_get_cycles();
    1823 if( DEBUG_PROCESS_TXT < cycle )
    1824 printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n",
    1825 __FUNCTION__, CURRENT_THREAD, process_pid, cycle );
    1826 #endif
    18271800
    18281801    // get extended pointer on stdin pseudo file
     
    18381811
    18391812#if DEBUG_PROCESS_TXT
    1840 cycle = (uint32_t)hal_get_cycles();
     1813uint32_t cycle  = (uint32_t)hal_get_cycles();
     1814uint32_t txt_id = hal_remote_lw( XPTR( txt_cxy , &txt_ptr->channel ) );
    18411815if( DEBUG_PROCESS_TXT < cycle )
    1842 printk("\n[DBG] %s : thread %x exit for process %x / cycle %d\n",
    1843 __FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     1816printk("\n[DBG] %s : thread %x in process %x give TXT %d to process %x / cycle %d\n",
     1817__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, txt_id, process_pid, cycle );
    18441818#endif
    18451819
     
    18651839    cxy_t       current_cxy;     // cluster for current process
    18661840
     1841#if DEBUG_PROCESS_TXT
     1842uint32_t cycle;
     1843#endif
     1844
    18671845    // get pointers on process in owner cluster
    18681846    process_cxy = GET_CXY( process_xp );
    18691847    process_ptr = GET_PTR( process_xp );
    1870 
    1871     // get process PID
    18721848    process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
    18731849
     
    18751851    assert( (process_cxy == CXY_FROM_PID( process_pid )) , __FUNCTION__,
    18761852    "process descriptor not in owner cluster\n" );
    1877 
    1878 #if DEBUG_PROCESS_TXT
    1879 uint32_t cycle = (uint32_t)hal_get_cycles();
    1880 if( DEBUG_PROCESS_TXT < cycle )
    1881 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
    1882 __FUNCTION__, CURRENT_THREAD, process_pid, cycle );
    1883 #endif
    18841853
    18851854    // get extended pointer on stdin pseudo file
     
    18951864    txt_id   = hal_remote_lw ( XPTR( txt_cxy , &txt_ptr->channel ) );
    18961865
    1897 #if( DEBUG_PROCESS_TXT & 1 )
    1898 if( DEBUG_PROCESS_TXT < cycle )
    1899 printk("\n[DBG] %s : file_ptr %x / txt_ptr %x / txt_id %d / owner_ptr = %x\n",
    1900 __FUNCTION__, GET_PTR(file_xp), txt_ptr, txt_id, GET_PTR(owner_xp) );
    1901 #endif
    1902 
    19031866    // transfer ownership only if process is the TXT owner
    19041867    if( (owner_xp == process_xp) && (txt_id > 0) ) 
     
    19131876        if( process_get_ppid( process_xp ) != 1 )           // process is not KSH
    19141877        {
    1915 
    1916 #if( DEBUG_PROCESS_TXT & 1 )
    1917 if( DEBUG_PROCESS_TXT < cycle )
    1918 printk("\n[DBG] %s : process is not the KSH process => search the KSH\n", __FUNCTION__ );
    1919 #endif
    19201878            // scan attached process list to find KSH process
    19211879            XLIST_FOREACH( root_xp , iter_xp )
     
    19341892
    19351893#if DEBUG_PROCESS_TXT
    1936 cycle = (uint32_t)hal_get_cycles();
     1894cycle   = (uint32_t)hal_get_cycles();
     1895uint32_t ksh_pid = hal_remote_lw( XPTR( current_cxy , &current_ptr->pid ) );
    19371896if( DEBUG_PROCESS_TXT < cycle )
    1938 printk("\n[DBG] %s : thread %x exit / process %x to KSH process %x / cycle %d\n",
    1939 __FUNCTION__, CURRENT_THREAD, process_pid,
    1940 hal_remote_lw( XPTR( current_cxy , &current_ptr->pid ) ), cycle );
     1897printk("\n[DBG] %s : thread %x in process %x release TXT %d to KSH %x / cycle %d\n",
     1898__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, txt_id, ksh_pid, cycle );
     1899process_txt_display( txt_id );
    19411900#endif
    19421901                     return;
     
    19541913        else                                               // process is KSH
    19551914        {
    1956 
    1957 #if( DEBUG_PROCESS_TXT & 1 )
    1958 if( DEBUG_PROCESS_TXT < cycle )
    1959 printk("\n[DBG] %s : process is the KSH process => search another\n", __FUNCTION__ );
    1960 #endif
    1961 
    19621915            // scan attached process list to find another process
    19631916            XLIST_FOREACH( root_xp , iter_xp )
     
    19761929
    19771930#if DEBUG_PROCESS_TXT
    1978 cycle = (uint32_t)hal_get_cycles();
     1931cycle   = (uint32_t)hal_get_cycles();
     1932uint32_t new_pid = hal_remote_lw( XPTR( current_cxy , &current_ptr->pid ) );
    19791933if( DEBUG_PROCESS_TXT < cycle )
    1980 printk("\n[DBG] %s : thread %x exit / KSH process %x to process %x / cycle %d\n",
    1981 __FUNCTION__, CURRENT_THREAD, process_pid,
    1982 hal_remote_lw( XPTR( current_cxy , &current_ptr->pid ) ), cycle );
     1934printk("\n[DBG] %s : thread %x in process %x release TXT %d to process %x / cycle %d\n",
     1935__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, txt_id, new_pid, cycle );
     1936process_txt_display( txt_id );
    19831937#endif
    19841938                     return;
     
    19951949cycle = (uint32_t)hal_get_cycles();
    19961950if( DEBUG_PROCESS_TXT < cycle )
    1997 printk("\n[DBG] %s : thread %x exit / KSH process %x to nobody / cycle %d\n",
    1998 __FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     1951printk("\n[DBG] %s : thread %x in process %x release TXT %d to nobody / cycle %d\n",
     1952__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, txt_id, cycle );
     1953process_txt_display( txt_id );
    19991954#endif
    20001955            return;
     
    20071962cycle = (uint32_t)hal_get_cycles();
    20081963if( DEBUG_PROCESS_TXT < cycle )
    2009 printk("\n[DBG] %s : thread %x exit / process %x is not TXT owner / cycle %d\n",
    2010 __FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     1964printk("\n[DBG] %s : thread %x in process %d does nothing (not TXT owner) / cycle %d\n",
     1965__FUNCTION__, CURRENT_THREAD->trdid, process_pid, cycle );
     1966process_txt_display( txt_id );
    20111967#endif
    20121968
     
    20141970}  // end process_txt_transfer_ownership()
    20151971
     1972
     1973//////////////////////////////////////////////////
     1974uint32_t process_txt_is_owner( xptr_t process_xp )
     1975{
     1976    // get local pointer and cluster of process in owner cluster
     1977    cxy_t       process_cxy = GET_CXY( process_xp );
     1978    process_t * process_ptr = GET_PTR( process_xp );
     1979
     1980    // check owner cluster
     1981    pid_t process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
     1982    assert( (process_cxy == CXY_FROM_PID( process_pid )) , __FUNCTION__,
     1983    "process descriptor not in owner cluster\n" );
     1984
     1985    // get extended pointer on stdin pseudo file
     1986    xptr_t file_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
     1987
     1988    // get pointers on TXT chdev
     1989    xptr_t    txt_xp  = chdev_from_file( file_xp );
     1990    cxy_t     txt_cxy = GET_CXY( txt_xp );
     1991    chdev_t * txt_ptr = GET_PTR( txt_xp );
     1992
     1993    // get extended pointer on TXT_RX owner process
     1994    xptr_t owner_xp = hal_remote_lwd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );
     1995
     1996    return (process_xp == owner_xp);
     1997
     1998}   // end process_txt_is_owner()
    20161999
    20172000////////////////////////////////////////////////     
     
    20232006
    20242007    return (xptr_t)hal_remote_lwd( XPTR( txt_rx_cxy , &txt_rx_ptr->ext.txt.owner_xp ) );
    2025 }
     2008
     2009}  // end process_txt_get_owner()
    20262010
    20272011///////////////////////////////////////////
  • trunk/kernel/kern/process.h

    r450 r457  
    2929#include <kernel_config.h>
    3030#include <errno.h>
    31 #include <hal_types.h>
     31#include <hal_kernel_types.h>
    3232#include <list.h>
    3333#include <xlist.h>
     
    146146
    147147    uint32_t          term_state;       /*! termination status (flags & exit status)        */
    148 
    149     bool_t            txt_owner;        /*! current TXT owner                               */
    150148}
    151149process_t;
     
    213211/*********************************************************************************************
    214212 * This function initializes a local, reference, user process descriptor from another process
    215  * descriptor, defined by the <model_xp> argument. The <process> and <pid> arguments must
    216  * be previously allocated by he caller. This function can be called by three functions:
    217  * 1) process_init_create() : process is the reference INIT process / pid = 1 /
    218  *    the parent and model process descriptors are both the kernel process_zero.
    219  * 2) process_make_fork() : the model process descriptor is the (generally remote)
    220  *    parent process.
    221  * 3) process_make exec() : the model process is the local old_process, the new_process
    222  *    parent is the same as the old_process parent.
     213 * descriptor, defined by the <parent_xp> argument. The <process> and <pid> arguments must
     214 * be previously allocated by the caller. This function can be called by two functions:
     215 * 1) process_init_create() : process is the INIT process; parent is process-zero.
     216 * 2) process_make_fork() : the parent process descriptor is generally remote.
    223217 * The following fields are initialised :
    224218 * - It set the pid / ppid / ref_xp / parent_xp / state fields.
    225219 * - It initializes the VMM (register the kentry, args, envs vsegs in VSL)
    226220 * - It initializes the FDT, defining the three pseudo files STDIN / STDOUT / STDERR.
     221 *   . if INIT process     => link to kernel TXT[0].
     222 *   . if KSH[i] process   => allocate a free TXT[i] and give TXT ownership.
     223 *   . if USER process     => same TXT[i] as parent process and give TXT ownership.
    227224 * - It set the root_xp, bin_xp, cwd_xp fields.
    228225 * - It reset the children list as empty, but does NOT register it in parent children list.
     
    236233 * @ pid          : [in] process identifier.
    237234 * @ parent_xp    : [in] extended pointer on parent process descriptor.
    238  * @ model_xp     : [in] extended pointer on model process descriptor.
    239235 ********************************************************************************************/
    240236void process_reference_init( process_t * process,
    241237                             pid_t       pid,
    242                              xptr_t      parent_xp,
    243                              xptr_t      model_xp );
     238                             xptr_t      parent_xp );
    244239
    245240/*********************************************************************************************
     
    515510 * It is called only by the process_reference_init() function when creating a KSH process.
    516511 * It makes a kernel panic if no free TXT terminal is found.
    517  * The allocated TXT terminal is only released if the KSH process is deleted,
    518  * which is a rare and abnormal event.
     512 * The allocated TXT terminal is only released when the KSH process is deleted.
    519513 *********************************************************************************************
    520514 * @ return TXT terminal index if succes / kernel panic if no terminal found.
     
    547541
    548542/*********************************************************************************************
    549  * This function gives to a process identified by the <owner_xp> argument, and attached
    550  * to terminal TXT[i] the exclusive ownership of the TXT_RX[i] terminal.
    551  * The process descriptor must be in the process owner cluster.
     543 * This function gives the TXT ownership to a process identified by the <process_xp> argument.
     544 * It can be called by a thread running in any cluster, but the <process_xp> must be the
     545 * owner cluster process descriptor.
    552546 *********************************************************************************************
    553547 * @ owner_xp  : extended pointer on process descriptor in owner cluster.
    554548 ********************************************************************************************/
    555 void process_txt_set_ownership( xptr_t owner_xp );
    556 
    557 /*********************************************************************************************
    558  * When the process dentified by the <owner_xp> argument has the exclusive ownership of
     549void process_txt_set_ownership( xptr_t process_xp );
     550
     551/*********************************************************************************************
     552 * When the process identified by the <owner_xp> argument has the exclusive ownership of
    559553 * the TXT_RX terminal, this function transfer this ownership to another attached process.
    560554 * The process descriptor must be the process owner.
     
    565559 * - If there is no other attached process, the TXT has no more defined owner.
    566560 *********************************************************************************************
    567  * @ owner_xp  : extended pointer on process descriptor in owner cluster.
    568  ********************************************************************************************/
    569 void process_txt_transfer_ownership( xptr_t owner_xp );
    570 
    571 /*********************************************************************************************
    572  * This function returns the TXT owner process (foreground process)
    573  * for a given TXT terminal identified by its <channel> index.
    574  *********************************************************************************************
    575  * @ channel  : TXT terminal channel.
    576  * @ return extentded pointer on TXT owner process in owner cluster.
     561 * @ process_xp  : extended pointer on process descriptor in owner cluster.
     562 ********************************************************************************************/
     563void process_txt_transfer_ownership( xptr_t process_xp );
     564
     565/*********************************************************************************************
     566 * This function returns true if the  process identified by the <process_xp> argument
     567 * is the TXT owner. It can be called by a thread running in any cluster, but the
     568 * process_xp must be the owner cluster process descriptor.
     569 *********************************************************************************************
     570 * @ return a non-zero value if target process is TXT owner.
     571 ********************************************************************************************/
     572uint32_t process_txt_is_owner( xptr_t process_xp );
     573
     574/*********************************************************************************************
     575 * This function returns an extended ponter on the current TXT owner process,
     576 * for the TXT terminal identified by the <channel> index.
     577 *********************************************************************************************
     578 * @ channel : TXT channel.
     579 * @ return extended pointer on TXT owner process.
    577580 ********************************************************************************************/
    578581xptr_t process_txt_get_owner( uint32_t channel );
  • trunk/kernel/kern/rpc.c

    r450 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_atomic.h>
    2727#include <hal_remote.h>
     
    100100    volatile error_t   full;
    101101    thread_t         * this;
    102     cluster_t        * cluster;
    103 
    104 #if DEBUG_RPC_CLIENT_GENERIC
    105 uint32_t cycle = (uint32_t)hal_get_cycles();
    106 if( DEBUG_RPC_CLIENT_GENERIC < cycle )
    107 printk("\n[DBG] %s : thread %x in cluster %x enter for rpc[%d] / rpc_ptr %x / cycle %d\n",
    108 __FUNCTION__, CURRENT_THREAD, local_cxy, rpc->index, rpc, cycle );
    109 #endif
    110102
    111103    full            = 0;
    112104    this            = CURRENT_THREAD;
    113     cluster         = LOCAL_CLUSTER;
    114105    client_core_lid = this->core->lid;
    115106
     107#if DEBUG_RPC_CLIENT_GENERIC
     108uint32_t cycle = (uint32_t)hal_get_cycles();
     109if( DEBUG_RPC_CLIENT_GENERIC < cycle )
     110printk("\n[DBG] %s : thread %x in process %x enter for rpc[%d] / cycle %d\n",
     111__FUNCTION__, this->trdid, this->process->pid, rpc->index, cycle );
     112#endif
     113
    116114    // select a server_core : use client core index if possible / core 0 otherwise
    117     if( client_core_lid < hal_remote_lw( XPTR( server_cxy , &cluster->cores_nr ) ) )
     115    if( client_core_lid < hal_remote_lw( XPTR( server_cxy , &LOCAL_CLUSTER->cores_nr ) ) )
    118116    {
    119117        server_core_lid = client_core_lid;
     
    150148 
    151149    hal_fence();
     150
     151#if DEBUG_RPC_CLIENT_GENERIC
     152cycle = (uint32_t)hal_get_cycles();
     153if( DEBUG_RPC_CLIENT_GENERIC < cycle )
     154printk("\n[DBG] %s : thread %x in process %x / rpc[%d] / rpc_ptr %x / cycle %d\n",
     155__FUNCTION__, this->trdid, this->process->pid, rpc->index, rpc, cycle );
     156#endif
    152157       
    153     // send IPI to the selected server core
    154         dev_pic_send_ipi( server_cxy , server_core_lid );
     158   // send IPI to the selected server core
     159   dev_pic_send_ipi( server_cxy , server_core_lid );
    155160
    156161    // wait RPC completion before returning if blocking RPC
     
    165170cycle = (uint32_t)hal_get_cycles();
    166171if( DEBUG_RPC_CLIENT_GENERIC < cycle )
    167 printk("\n[DBG] %s : thread %x in cluster %x busy waiting / rpc[%d] / cycle %d\n",
    168 __FUNCTION__, CURRENT_THREAD, local_cxy, rpc->index , cycle );
     172printk("\n[DBG] %s : thread %x in process %x busy waiting for rpc[%d] / cycle %d\n",
     173__FUNCTION__, this->trdid, this->process->pid, rpc->index , cycle );
    169174#endif
    170175
     
    174179cycle = (uint32_t)hal_get_cycles();
    175180if( DEBUG_RPC_CLIENT_GENERIC < cycle )
    176 printk("\n[DBG] %s : thread %x in cluster %x resumes / rpc[%d] / cycle %d\n",
    177 __FUNCTION__, CURRENT_THREAD, local_cxy, rpc->index, cycle );
     181printk("\n[DBG] %s : thread %x in process %x resumes for rpc[%d] / cycle %d\n",
     182__FUNCTION__, this->trdid, this->process->pid, rpc->index, cycle );
    178183#endif
    179184        }
     
    184189cycle = (uint32_t)hal_get_cycles();
    185190if( DEBUG_RPC_CLIENT_GENERIC < cycle )
    186 printk("\n[DBG] %s : thread %x in cluster %x blocks & deschedules / rpc[%d] / cycle %d\n",
    187 __FUNCTION__, CURRENT_THREAD, local_cxy, rpc->index , cycle );
     191printk("\n[DBG] %s : thread %x in process %x blocks & deschedules for rpc[%d] / cycle %d\n",
     192__FUNCTION__, this->trdid, this->process->pid, rpc->index , cycle );
    188193#endif
    189194            thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_RPC );
     
    193198cycle = (uint32_t)hal_get_cycles();
    194199if( DEBUG_RPC_CLIENT_GENERIC < cycle )
    195 printk("\n[DBG] %s : thread %x in cluster %x resumes / rpcr[%d] / cycle %d\n",
    196 __FUNCTION__, CURRENT_THREAD, local_cxy, rpc->index, cycle );
     200printk("\n[DBG] %s : thread %x in process %x resumes for rpc[%d] / cycle %d\n",
     201__FUNCTION__, this->trdid, this->process->pid, rpc->index, cycle );
    197202#endif
    198203        }
     
    207212cycle = (uint32_t)hal_get_cycles();
    208213if( DEBUG_RPC_CLIENT_GENERIC < cycle )
    209 printk("\n[DBG] %s : non blocking rpc[%d] => thread %x return / cycle %d\n",
    210 __FUNCTION__, rpc->index, CURRENT_THREAD, cycle );
     214printk("\n[DBG] %s : thread %x in process %x returns for non blocking rpc[%d] / cycle %d\n",
     215__FUNCTION__, this->trdid, this->process->pid, rpc->index, cycle );
    211216#endif
    212217
     
    225230    thread_t      * thread; 
    226231    uint32_t        sr_save;
     232
     233#if DEBUG_RPC_SERVER_GENERIC
     234uint32_t cycle;
     235#endif
    227236
    228237    bool_t          found    = false;
     
    232241        remote_fifo_t * rpc_fifo = &LOCAL_CLUSTER->rpc_fifo[core->lid];
    233242
    234 #if DEBUG_RPC_SERVER_GENERIC
    235 uint32_t cycle = (uint32_t)hal_get_cycles();
    236 if( DEBUG_RPC_SERVER_GENERIC < cycle )
    237 printk("\n[DBG] %s : thread %x interrupted in cluster %x / cycle %d\n",
    238 __FUNCTION__, this, local_cxy, cycle );
    239 #endif
    240 
    241243    // interrupted thread not preemptable during RPC chek
    242244        hal_disable_irq( &sr_save );
     
    249251cycle = (uint32_t)hal_get_cycles();
    250252if( DEBUG_RPC_SERVER_GENERIC < cycle )
    251 printk("\n[DBG] %s : RPC FIFO non empty in cluster %x / cycle %d\n",
    252 __FUNCTION__, local_cxy, cycle );
     253printk("\n[DBG] %s : RPC FIFO non empty for core[%x,%d] / cycle %d\n",
     254__FUNCTION__, local_cxy, core->lid, cycle );
    253255#endif
    254256
     
    290292cycle = (uint32_t)hal_get_cycles();
    291293if( DEBUG_RPC_SERVER_GENERIC < cycle )
    292 printk("\n[DBG] %s : create a new RPC thread %x in cluster %x / cycle %d\n",
    293 __FUNCTION__, thread, local_cxy, cycle );
     294printk("\n[DBG] %s : new RPC thread %x created for core[%x,%d] / cycle %d\n",
     295__FUNCTION__, thread, local_cxy, core->lid, cycle );
    294296#endif
    295297        }
     
    299301cycle = (uint32_t)hal_get_cycles();
    300302if( DEBUG_RPC_SERVER_GENERIC < cycle )
    301 printk("\n[DBG] %s : interrupted thread %x deschedules in cluster %x / cycle %d\n",
    302 __FUNCTION__, this, local_cxy, cycle );
     303printk("\n[DBG] %s : interrupted thread %x deschedules on core[%x,%d] / cycle %d\n",
     304__FUNCTION__, this, local_cxy, core->lid, cycle );
    303305#endif
    304306
     
    309311cycle = (uint32_t)hal_get_cycles();
    310312if( DEBUG_RPC_SERVER_GENERIC < cycle )
    311 printk("\n[DBG] %s : interrupted thread %x resumes in cluster %x / cycle %d\n",
    312 __FUNCTION__, this, local_cxy, cycle );
     313printk("\n[DBG] %s : interrupted thread %x resumes on core[%x,%d] / cycle %d\n",
     314__FUNCTION__, this, local_cxy, core->lid, cycle );
    313315#endif
    314316
     
    410412#endif
    411413                        // send IPI to client core
    412                             dev_pic_send_ipi( desc_cxy , client_core_lid );
     414                            // dev_pic_send_ipi( desc_cxy , client_core_lid );
    413415                    }
    414416                        }
     
    872874pid_t     pid    = rpc->args[1];
    873875if( DEBUG_RPC_PROCESS_SIGACTION < cycle )
    874 printk("\n[DBG] %s : enter to %s process %x in cluster %x / cycle %d\n",
     876printk("\n[DBG] %s : enter to request %s of process %x in cluster %x / cycle %d\n",
    875877__FUNCTION__ , process_action_str( action ) , pid , cxy , cycle );
    876878#endif
     
    949951
    950952        // send an IPI to client core
    951         dev_pic_send_ipi( client_cxy , client_lid );
     953        // dev_pic_send_ipi( client_cxy , client_lid );
    952954    }
    953955
  • trunk/kernel/kern/rpc.h

    r450 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <hal_atomic.h>
    3030#include <bits.h>
  • trunk/kernel/kern/scheduler.c

    r450 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_switch.h>
    2727#include <hal_irqmask.h>
  • trunk/kernel/kern/scheduler.h

    r450 r457  
    2525#define _SCHEDULER_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <list.h>
    2929#include <spinlock.h>
  • trunk/kernel/kern/signal.c

    r409 r457  
    2424 */
    2525
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727#include <printk.h>
    2828#include <signal.h>
  • trunk/kernel/kern/signal.h

    r435 r457  
    2727#define _SIGNAL_H_
    2828
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030
    3131
  • trunk/kernel/kern/thread.c

    r450 r457  
    2424
    2525#include <kernel_config.h>
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727#include <hal_context.h>
    2828#include <hal_irqmask.h>
     
    167167    thread->quantum         = 0;            // TODO
    168168    thread->ticks_nr        = 0;            // TODO
    169     thread->time_last_check = 0;
     169    thread->time_last_check = 0;            // TODO
    170170        thread->core            = &local_cluster->core_tbl[core_lid];
    171171        thread->process         = process;
     
    243243uint32_t cycle = (uint32_t)hal_get_cycles();
    244244if( DEBUG_THREAD_USER_CREATE < cycle )
    245 printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
    246 __FUNCTION__, CURRENT_THREAD, pid , local_cxy , cycle );
     245printk("\n[DBG] %s : thread %x in process %x enter in cluster %x / cycle %d\n",
     246__FUNCTION__, CURRENT_THREAD->trdid, pid , local_cxy , cycle );
    247247#endif
    248248
     
    301301    }
    302302
     303#if( DEBUG_THREAD_USER_CREATE & 1)
     304if( DEBUG_THREAD_USER_CREATE < cycle )
     305printk("\n[DBG] %s : stack vseg created / vpn_base %x / %d pages\n",
     306__FUNCTION__, vseg->vpn_base, vseg->vpn_size );
     307#endif
     308
    303309    // allocate memory for thread descriptor
    304310    thread = thread_alloc();
     
    313319#if( DEBUG_THREAD_USER_CREATE & 1)
    314320if( DEBUG_THREAD_USER_CREATE < cycle )
    315 printk("\n[DBG] %s : thread descriptor %x allocated\n",
     321printk("\n[DBG] %s : new thread descriptor %x allocated\n",
    316322__FUNCTION__, thread );
    317323#endif
     
    336342#if( DEBUG_THREAD_USER_CREATE & 1)
    337343if( DEBUG_THREAD_USER_CREATE < cycle )
    338 printk("\n[DBG] %s : thread descriptor %x initialised / trdid = %x\n",
    339 __FUNCTION__, thread , thread->trdid );
     344printk("\n[DBG] %s : new thread descriptor initialised / trdid %x\n",
     345__FUNCTION__, thread->trdid );
    340346#endif
    341347
     
    347353
    348354    // allocate & initialize CPU context
    349         if( hal_cpu_context_create( thread ) )
     355        if( hal_cpu_context_alloc( thread ) )
    350356    {
    351357            printk("\n[ERROR] in %s : cannot create CPU context\n", __FUNCTION__ );
     
    354360        return ENOMEM;
    355361    }
    356 
    357     // allocate  FPU context
     362    hal_cpu_context_init( thread );
     363
     364    // allocate & initialize FPU context
    358365    if( hal_fpu_context_alloc( thread ) )
    359366    {
     
    363370        return ENOMEM;
    364371    }
     372    hal_fpu_context_init( thread );
     373
     374#if( DEBUG_THREAD_USER_CREATE & 1)
     375if( DEBUG_THREAD_USER_CREATE < cycle )
     376printk("\n[DBG] %s : CPU & FPU contexts created\n",
     377__FUNCTION__, thread->trdid );
     378vmm_display( process , true );
     379#endif
    365380
    366381#if DEBUG_THREAD_USER_CREATE
    367382cycle = (uint32_t)hal_get_cycles();
    368383if( DEBUG_THREAD_USER_CREATE < cycle )
    369 printk("\n[DBG] %s : thread %x exit / new_thread %x in process %x / core %d / cycle %d\n",
    370 __FUNCTION__, CURRENT_THREAD, thread->trdid , pid , core_lid, cycle );
     384printk("\n[DBG] %s : thread %x in process %x exit / new_thread %x / core %d / cycle %d\n",
     385__FUNCTION__, CURRENT_THREAD->trdid , pid, thread->trdid, core_lid, cycle );
    371386#endif
    372387
     
    554569}  // end thread_user_fork()
    555570
     571////////////////////////////////////////////////
     572error_t thread_user_exec( void     * entry_func,
     573                          uint32_t   argc,
     574                          char    ** argv )
     575{
     576    thread_t  * thread  = CURRENT_THREAD;
     577    process_t * process = thread->process;
     578
     579#if DEBUG_THREAD_USER_EXEC
     580uint32_t cycle = (uint32_t)hal_get_cycles();
     581if( DEBUG_THREAD_USER_EXEC < cycle )
     582printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n",
     583__FUNCTION__, thread->trdid, process->pid, cycle );
     584#endif
     585
     586        assert( (thread->type == THREAD_USER )          , __FUNCTION__, "bad type" );
     587        assert( (thread->signature == THREAD_SIGNATURE) , __FUNCTION__, "bad signature" );
     588        assert( (thread->local_locks == 0)              , __FUNCTION__, "bad local locks" );
     589        assert( (thread->remote_locks == 0)             , __FUNCTION__, "bad remote locks" );
     590
     591        // re-initialize various thread descriptor fields
     592    thread->quantum         = 0;            // TODO
     593    thread->ticks_nr        = 0;            // TODO
     594    thread->time_last_check = 0;            // TODO
     595
     596#if CONFIG_LOCKS_DEBUG
     597    list_root_init( &thread->locks_root ); 
     598    xlist_root_init( XPTR( local_cxy , &thread->xlocks_root ) );
     599#endif
     600
     601    thread->entry_func      = entry_func;
     602    thread->main_argc       = argc;
     603    thread->main_argv       = argv;
     604
     605    // the main thread is always detached
     606    thread->flags           = THREAD_FLAG_DETACHED;
     607    thread->blocked         = 0;
     608    thread->errno           = 0;
     609    thread->fork_user       = 0;    // not inherited
     610    thread->fork_cxy        = 0;    // not inherited
     611
     612    // reset thread info
     613    memset( &thread->info , 0 , sizeof(thread_info_t) );
     614
     615    // initialize join_lock
     616    remote_spinlock_init( XPTR( local_cxy , &thread->join_lock ) );
     617
     618    // allocate an user stack vseg for main thread
     619    vseg_t * vseg = vmm_create_vseg( process,
     620                                     VSEG_TYPE_STACK,
     621                                     0,                 // size unused
     622                                     0,                 // length unused
     623                                     0,                 // file_offset unused
     624                                     0,                 // file_size unused
     625                                     XPTR_NULL,         // mapper_xp unused
     626                                     local_cxy );
     627    if( vseg == NULL )
     628    {
     629            printk("\n[ERROR] in %s : cannot create stack vseg for main thread\n", __FUNCTION__ );
     630                return -1;
     631    }
     632
     633    // update user stack in stack descriptor
     634    thread->u_stack_base = vseg->min;
     635    thread->u_stack_size = vseg->max - vseg->min;
     636   
     637    // release FPU ownership if required
     638    if( thread->core->fpu_owner == thread ) thread->core->fpu_owner = NULL;
     639
     640    // re-initialize  FPU context
     641    hal_fpu_context_init( thread );
     642
     643#if DEBUG_THREAD_USER_EXEC
     644cycle = (uint32_t)hal_get_cycles();
     645if( DEBUG_THREAD_USER_EXEC < cycle )
     646printk("\n[DBG] %s : thread %x in process %x set CPU context & jump to user code / cycle %d\n",
     647__FUNCTION__, thread->trdid, process->pid, cycle );
     648vmm_display( process , true );
     649#endif
     650
     651    // re-initialize CPU context... and jump to user code
     652        hal_cpu_context_exec( thread );
     653
     654    assert( false, __FUNCTION__, "we should execute this code");
     655 
     656    return 0;
     657
     658}  // end thread_user_exec()
     659
    556660/////////////////////////////////////////////////////////
    557661error_t thread_kernel_create( thread_t     ** new_thread,
     
    594698    {
    595699        thread_release( thread );
     700        return ENOMEM;
     701    }
     702
     703    // allocate & initialize CPU context
     704        error = hal_cpu_context_alloc( thread );
     705    if( error )
     706    {
     707        thread_release( thread );
    596708        return EINVAL;
    597709    }
    598 
    599     // allocate & initialize CPU context
    600         hal_cpu_context_create( thread );
     710    hal_cpu_context_init( thread );
     711
    601712
    602713#if DEBUG_THREAD_KERNEL_CREATE
     
    612723} // end thread_kernel_create()
    613724
    614 /////////////////////////////////////////////////
    615 error_t thread_idle_init( thread_t      * thread,
    616                           thread_type_t   type,
    617                           void          * func,
    618                           void          * args,
    619                                           lid_t           core_lid )
     725//////////////////////////////////////////////
     726void thread_idle_init( thread_t      * thread,
     727                       thread_type_t   type,
     728                       void          * func,
     729                       void          * args,
     730                           lid_t           core_lid )
    620731{
    621732    assert( (type == THREAD_IDLE) , __FUNCTION__ , "illegal thread type" );
    622 
    623733    assert( (core_lid < LOCAL_CLUSTER->cores_nr) , __FUNCTION__ , "illegal core index" );
    624734
     735    // initialize thread descriptor
    625736    error_t  error = thread_init( thread,
    626737                                  &process_zero,
     
    631742                                  0 , 0 );   // no user stack for a kernel thread
    632743
     744    assert( (error == 0), __FUNCTION__, "cannot create thread idle" );
     745
    633746    // allocate & initialize CPU context if success
    634     if( error == 0 ) hal_cpu_context_create( thread );
    635 
    636     return error;
     747    error = hal_cpu_context_alloc( thread );
     748
     749    assert( (error == 0), __FUNCTION__, "cannot allocate CPU context" );
     750
     751    hal_cpu_context_init( thread );
    637752
    638753}  // end thread_idle_init()
     
    798913
    799914#if DEBUG_THREAD_BLOCK
    800 uint32_t cycle = (uint32_t)hal_get_cycles();
     915uint32_t    cycle   = (uint32_t)hal_get_cycles();
     916process_t * process = hal_remote_lpt( XPTR( cxy , &ptr->process ) );
    801917if( DEBUG_THREAD_BLOCK < cycle )
    802 printk("\n[DBG] %s : thread %x  in cxy %x blocked thread %x in cxy %x / cause %x / cycle %d\n",
    803 __FUNCTION__ , CURRENT_THREAD , local_cxy , ptr , cxy , cause , cycle );
     918printk("\n[DBG] %s : thread %x in process %x blocked thread %x in process %x / cause %x\n",
     919__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
     920ptr->trdid, hal_remote_lw(XPTR( cxy , &process->pid )), cause );
    804921#endif
    805922
     
    819936
    820937#if DEBUG_THREAD_BLOCK
    821 uint32_t cycle = (uint32_t)hal_get_cycles();
     938uint32_t    cycle   = (uint32_t)hal_get_cycles();
     939process_t * process = hal_remote_lpt( XPTR( cxy , &ptr->process ) );
    822940if( DEBUG_THREAD_BLOCK < cycle )
    823 printk("\n[DBG] %s : thread %x  in cxy %x unblocked thread %x in cxy %x / cause %x / cycle %d\n",
    824 __FUNCTION__ , CURRENT_THREAD , local_cxy , ptr , cxy , cause , cycle );
     941printk("\n[DBG] %s : thread %x in process %x unblocked thread %x in process %x / cause %x\n",
     942__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
     943ptr->trdid, hal_remote_lw(XPTR( cxy , &process->pid )), cause );
    825944#endif
    826945
  • trunk/kernel/kern/thread.h

    r446 r457  
    2626#define _THREAD_H_
    2727
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <shared_syscalls.h>
    3030#include <hal_special.h>
     
    161161    void              * entry_func;      /*! pointer on entry function                */
    162162    void              * entry_args;      /*! pointer on entry function arguments      */
     163    uint32_t            main_argc;       /*! main thread number of arguments          */
     164    char             ** main_argv;       /*! main thread array of strings arguments   */
    163165
    164166    uint32_t            flags;           /*! bit vector of flags                      */
     
    218220 * The CPU context is initialized from scratch.
    219221 * It is registered in the local process descriptor specified by the <pid> argument.
    220  * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start.
     222 * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated by the caller
     223 * to start at the next scheduling point.
    221224 ***************************************************************************************
    222225 * @ pid          : process identifier.
     
    258261
    259262/***************************************************************************************
     263 * This function is called by the process_make_exec() function to re-initialise the
     264 * thread descriptor of the calling thread (that will become the new process main
     265 * thread), and immediately jump to user code without returning to kentry!!!
     266 * It must be called by the main thread of the calling process.
     267 * - A new user stack vseg is created and initialised.
     268 * - The kernel stack (currently in use) is not modified. 
     269 * - The function calls the hal_cpu_context_exec() to re-initialize the CPU context
     270 *   an jump to user code. 
     271 ***************************************************************************************
     272 * @ entry_func : main thread entry point.
     273 * @ argc       : number of main thread arguments.
     274 * @ argv       : array of pointers on stringarguments.
     275 * @ returns 0 if success / returns ENOMEM if error.
     276 **************************************************************************************/
     277error_t thread_user_exec( void     * entry_func,
     278                          uint32_t   argc,
     279                          char    ** argv);
     280
     281/***************************************************************************************
    260282 * This function allocates memory for a kernel thread descriptor in the local cluster,
    261283 * and initializes it from arguments values.
     
    281303 * descriptor from arguments values.
    282304 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.
     305 * It returns a kernel panic if failure.
    283306 ***************************************************************************************
    284307 * @ thread   : pointer on existing thread descriptor.
     
    287310 * @ args     : function arguments.
    288311 * @ core_lid : local core index.
    289  * @ returns 0 if success / returns EINVAL if error
    290  **************************************************************************************/
    291 error_t thread_idle_init( thread_t      * thread,
    292                           thread_type_t   type,
    293                           void          * func,
    294                           void          * args,
    295                           lid_t           core_lid );
     312 **************************************************************************************/
     313void thread_idle_init( thread_t      * thread,
     314                       thread_type_t   type,
     315                       void          * func,
     316                       void          * args,
     317                       lid_t           core_lid );
    296318
    297319/***************************************************************************************
  • trunk/kernel/kernel_config.h

    r450 r457  
    2727#define _ALMOS_CONFIG_H_
    2828
    29 #define CONFIG_ALMOS_VERSION                "Version 1.0 / March 2018"
     29#define CONFIG_ALMOS_VERSION           "Version 1.0 / August 2018"
    3030
    3131////////////////////////////////////////////////////////////////////////////////////////////
     
    7676#define DEBUG_HAL_IOC_RX               0
    7777#define DEBUG_HAL_IOC_TX               0
    78 #define DEBUG_HAL_GPT
     78#define DEBUG_HAL_GPT                  0
    7979
    8080#define DEBUG_KCM                      0
     
    117117
    118118#define DEBUG_SCHED_HANDLE_SIGNALS     2
    119 #define DEBUG_SCHED_YIELD              2    // must be activated by the trace() syscall
     119#define DEBUG_SCHED_YIELD              1    // must be activated by the trace() syscall
    120120
    121121#define DEBUG_SYSCALLS_ERROR           2
    122122
    123123#define DEBUG_SYS_DISPLAY              0
    124 #define DEBUG_SYS_EXEC                 1
    125 #define DEBUG_SYS_EXIT                 1
     124#define DEBUG_SYS_EXEC                 0
     125#define DEBUG_SYS_EXIT                 0
    126126#define DEBUG_SYS_FG                   0
    127127#define DEBUG_SYS_FORK                 0
    128128#define DEBUG_SYS_GET_CONFIG           0
    129129#define DEBUG_SYS_ISATTY               0
     130#define DEBUG_SYS_IS_FG                0
    130131#define DEBUG_SYS_KILL                 0
    131132#define DEBUG_SYS_MMAP                 0
     
    154155#define DEBUG_THREAD_USER_CREATE       0
    155156#define DEBUG_THREAD_USER_FORK         0
     157#define DEBUG_THREAD_USER_EXEC         0
    156158#define DEBUG_THREAD_BLOCK             0
    157159
  • trunk/kernel/libk/barrier.c

    r16 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <hal_atomic.h>
  • trunk/kernel/libk/barrier.h

    r423 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929
    3030/*****************************************************************************************
  • trunk/kernel/libk/bits.c

    r351 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <bits.h>
    2727
  • trunk/kernel/libk/bits.h

    r454 r457  
    2727
    2828#include <kernel_config.h>
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030
    3131/*********************************************************************************************
  • trunk/kernel/libk/ctype.c

    r1 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525
    2626////////////////////
  • trunk/kernel/libk/elf.c

    r441 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <hal_uspace.h>
     
    210210} // end elf_segments_register()
    211211
    212 ///////////////////////////////////////////////
    213 error_t elf_load_process( char      * pathname,
    214                           process_t * process)
     212//////////////////////////////////////////////
     213error_t elf_load_process( xptr_t      file_xp,
     214                          process_t * process )
    215215{
    216216        kmem_req_t   req;              // kmem request for program header
     
    218218        void       * segs_base;        // pointer on buffer for segment descriptors array
    219219        uint32_t     segs_size;        // size of buffer for segment descriptors array
    220         xptr_t       file_xp;          // extended pointer on created file descriptor
    221         uint32_t     file_id;          // file descriptor index (unused)
     220    char         name[CONFIG_VFS_MAX_NAME_LENGTH];
    222221        error_t      error;
    223222
     223    // get file name for error reporting and debug
     224    cxy_t         file_cxy = GET_CXY( file_xp );
     225    vfs_file_t  * file_ptr = GET_PTR( file_xp );
     226    vfs_inode_t * inode    = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
     227    vfs_inode_get_name( XPTR( file_cxy , inode ) , name );
     228   
    224229#if DEBUG_ELF_LOAD
    225 uint32_t cycle = (uint32_t)hal_get_cycles();
    226 if( DEBUG_ELF_LOAD < cycle )
    227 printk("\n[DBG] %s : thread %d enter for <%s> / cycle %d\n",
    228 __FUNCTION__, CURRENT_THREAD, pathname, cycle );
    229 #endif
    230 
    231     // avoid GCC warning
    232         file_xp = XPTR_NULL; 
    233         file_id = -1;
    234 
    235         // open file
    236         error = vfs_open( process,
    237                           pathname,
    238                           O_RDONLY,
    239                           0,
    240                           &file_xp,
    241                           &file_id );
    242         if( error )
    243         {
    244                 printk("\n[ERROR] in %s : failed to open file <%s>\n", __FUNCTION__ , pathname );
    245                 return -1;
    246         }
    247 
    248 #if (DEBUG_ELF_LOAD & 1)
    249 if( DEBUG_ELF_LOAD < cycle )
    250 printk("\n[DBG] %s : open file <%s>\n", __FUNCTION__, pathname );
     230uint32_t      cycle = (uint32_t)hal_get_cycles();
     231if( DEBUG_ELF_LOAD < cycle )
     232printk("\n[DBG] %s : thread %d in process %x enter for <%s> / cycle %d\n",
     233__FUNCTION__, CURRENT_THREAD->trdid, process->pid, name, cycle );
    251234#endif
    252235
     
    257240        if( error )
    258241        {
    259                 printk("\n[ERROR] in %s : cannot get header for <%s>\n", __FUNCTION__ , pathname );
    260                 vfs_close( file_xp , file_id );
     242                printk("\n[ERROR] in %s : cannot get header for <%s>\n", __FUNCTION__ , name );
    261243                return -1;
    262244        }
     
    264246#if (DEBUG_ELF_LOAD & 1)
    265247if( DEBUG_ELF_LOAD < cycle )
    266 printk("\n[DBG] %s : loaded elf header for <%s>\n", __FUNCTION__ , pathname );
     248printk("\n[DBG] %s : loaded elf header for <%s>\n", __FUNCTION__ , name );
    267249#endif
    268250
     
    270252        {
    271253                printk("\n[ERROR] in %s : no segments found\n", __FUNCTION__ );
    272                 vfs_close( file_xp , file_id );
    273254                return -1;
    274255        }
     
    286267        {
    287268                printk("\n[ERROR] in %s : no memory for segment descriptors\n", __FUNCTION__ );
    288                 vfs_close( file_xp , file_id );
    289269                return -1;
    290270        }
     
    296276        {
    297277                printk("\n[ERROR] in %s : cannot seek for descriptors array\n", __FUNCTION__ );
    298                 vfs_close( file_xp , file_id );
    299278                req.ptr = segs_base;
    300279                kmem_free( &req );
     
    304283#if (DEBUG_ELF_LOAD & 1)
    305284if( DEBUG_ELF_LOAD < cycle )
    306 printk("\n[DBG] %s : segments array allocated for <%s>\n", __FUNCTION__ , pathname );
     285printk("\n[DBG] %s : segments array allocated for <%s>\n", __FUNCTION__ , name );
    307286#endif
    308287
     
    316295        {
    317296                printk("\n[ERROR] in %s : cannot read segments descriptors\n", __FUNCTION__ );
    318                 vfs_close( file_xp , file_id );
    319297                req.ptr = segs_base;
    320298                kmem_free( &req );
     
    324302#if (DEBUG_ELF_LOAD & 1)
    325303if( DEBUG_ELF_LOAD < cycle )
    326 printk("\n[DBG] %s loaded segments descriptors for <%s>\n", __FUNCTION__ , pathname );
     304printk("\n[DBG] %s loaded segments descriptors for <%s>\n", __FUNCTION__ , name );
    327305#endif
    328306
     
    334312        if( error )
    335313        {
    336                 vfs_close( file_xp , file_id );
    337314                req.ptr = segs_base;
    338315                kmem_free( &req );
     
    353330cycle = (uint32_t)hal_get_cycles();
    354331if( DEBUG_ELF_LOAD < cycle )
    355 printk("\n[DBG] %s : thread %d exit for <%s> / entry_point %x / cycle %d\n",
    356 __FUNCTION__, CURRENT_THREAD, pathname, header.e_entry, cycle );
     332printk("\n[DBG] %s : thread %x in process %x exit for <%s> / entry_point %x / cycle %d\n",
     333__FUNCTION__, CURRENT_THREAD->trdid, process->pid, name, header.e_entry, cycle );
    357334#endif
    358335
  • trunk/kernel/libk/elf.h

    r273 r457  
    2222#define _ELF_H_ 1
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525
    2626/*
     
    204204#define PF_MASKPROC     0xf0000000      /* Processor-specific */
    205205
    206 #if defined(HAL_32BIT)
     206#if defined(HAL_ELF_32_BITS)
    207207#define Elf_Half  Elf32_Half
    208208#define Elf_Word  Elf32_Word
     
    213213#define Elf_Phdr  Elf32_Phdr
    214214#define ELFCLASS  ELFCLASS32
    215 #elif defined (HAL_64BIT)
     215#elif defined (HAL_ELF_64_BITS)
    216216#define Elf_Half  Elf64_Half
    217217#define Elf_Word  Elf64_Word
     
    224224#define ELFCLASS  ELFCLASS64
    225225#else
    226 #error "Must define HAL_64BIT/HAL_32BIT"
     226#error "Must define HAL_ELF_64_BITS / HAL_ELF_32_BITS"
    227227#endif
    228228
    229229/****************************************************************************************
    230  * This function registers in VMM the CODE and DATA vsegs defined in the .elf file.
     230 * This function registers in VMM of the process identified by the <process> argument
     231 * the CODE and DATA vsegs defined in the .elf open file descriptor <file_xp>.
    231232 * The segments are not loaded in memory.
    232233 * It also registers the process entry point in VMM.
    233234 ****************************************************************************************
    234  * @ pathname : local pointer on .elf file pathname (in kernel space).
     235 * @ file_xp  : extended pointer on .elf file descriptor.
    235236 * @ process  : local pointer on target process descriptor.
    236237 ***************************************************************************************/
    237 error_t elf_load_process( char      * pathname,
     238error_t elf_load_process( xptr_t      file_xp,
    238239                          process_t * process);
    239240
  • trunk/kernel/libk/grdxt.c

    r423 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <errno.h>
  • trunk/kernel/libk/grdxt.h

    r406 r457  
    2525#define _GRDXT_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828
    2929/*******************************************************************************************
  • trunk/kernel/libk/htab.c

    r423 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <htab.h>
  • trunk/kernel/libk/htab.h

    r23 r457  
    2626#define _HTAB_H_
    2727
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <rwlock.h>
    3030#include <list.h>
  • trunk/kernel/libk/list.h

    r450 r457  
    2727
    2828#include <kernel_config.h>
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030
    3131#ifndef NULL
  • trunk/kernel/libk/memcpy.c

    r113 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <printk.h>
    2626
  • trunk/kernel/libk/memcpy.h

    r113 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525
    2626
  • trunk/kernel/libk/readlock.c

    r124 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_atomic.h>
    2727#include <hal_special.h>
  • trunk/kernel/libk/readlock.h

    r14 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929
    3030/*******************************************************************************************
  • trunk/kernel/libk/remote_barrier.c

    r436 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <hal_irqmask.h>
  • trunk/kernel/libk/remote_barrier.h

    r23 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <remote_spinlock.h>
    3030#include <xlist.h>
  • trunk/kernel/libk/remote_condvar.c

    r436 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <hal_irqmask.h>
  • trunk/kernel/libk/remote_condvar.h

    r23 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <remote_spinlock.h>
    3030#include <xlist.h>
  • trunk/kernel/libk/remote_fifo.c

    r408 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_irqmask.h>
    2727#include <hal_remote.h>
  • trunk/kernel/libk/remote_fifo.h

    r407 r457  
    2727
    2828#include <kernel_config.h>
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030#include <printk.h>
    3131#include <errno.h>
  • trunk/kernel/libk/remote_mutex.c

    r436 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <hal_special.h>
  • trunk/kernel/libk/remote_mutex.h

    r23 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <xlist.h>
    3030
  • trunk/kernel/libk/remote_rwlock.c

    r438 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <hal_irqmask.h>
  • trunk/kernel/libk/remote_rwlock.h

    r438 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <xlist.h>
    3030
  • trunk/kernel/libk/remote_sem.c

    r436 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <thread.h>
     
    7575
    7676///////////////////////////////////////////
    77 error_t remote_sem_create( intptr_t  vaddr,
    78                            uint32_t  value )
    79 {
     77error_t remote_sem_create( intptr_t   vaddr,
     78                           uint32_t   value,
     79                           xptr_t     sem_xp_xp )
     80{
     81    remote_sem_t * sem_ptr;
    8082    xptr_t         sem_xp;
    81     remote_sem_t * sem_ptr;
    8283
    8384    // get pointer on local process descriptor
     
    103104    {
    104105        rpc_kcm_alloc_client( ref_cxy , KMEM_SEM , &sem_xp );
    105         sem_ptr = (remote_sem_t *)GET_PTR( sem_xp );
    106     }
    107 
    108     if( sem_xp == XPTR_NULL ) return ENOMEM;
     106        sem_ptr = GET_PTR( sem_xp );
     107    }
     108
     109    if( sem_xp == XPTR_NULL ) return -1;
    109110
    110111    // initialise semaphore
    111112    hal_remote_sw ( XPTR( ref_cxy , &sem_ptr->count ) , value );
    112113        hal_remote_spt( XPTR( ref_cxy , &sem_ptr->ident ) , (void *)vaddr );
    113 
    114114    remote_spinlock_init( XPTR( ref_cxy , &sem_ptr->lock ) );
    115115        xlist_root_init( XPTR( ref_cxy , &sem_ptr->root ) );
     
    119119    xptr_t root_xp = XPTR( ref_cxy , &ref_ptr->sem_root );
    120120    xptr_t xp_list = XPTR( ref_cxy , &sem_ptr->list );
    121 
    122121    remote_spinlock_lock( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
    123122    xlist_add_first( root_xp , xp_list );
    124123    remote_spinlock_unlock( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
    125124
     125    // write extended pointer on semaphore in calling thread buffer
     126    hal_remote_swd( sem_xp_xp , sem_xp );
     127
    126128    return 0;
    127129
    128 }  // en remote_sem_init()
     130}  // en remote_sem_create()
    129131 
    130132////////////////////////////////////////
     
    139141    // get reference process cluster and local pointer
    140142    cxy_t       ref_cxy = GET_CXY( ref_xp );
    141     process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     143    process_t * ref_ptr = GET_PTR( ref_xp );
    142144
    143145    // get semaphore cluster and local pointer
     
    148150    remote_spinlock_lock( XPTR( sem_cxy , &sem_ptr->lock ) );
    149151 
    150     // get remote pointer on waiting queue
    151     xptr_t root_xp = (xptr_t)hal_remote_lwd( XPTR( sem_cxy , &sem_ptr->root ) );
     152    // get remote pointer on waiting queue root
     153    xptr_t root_xp = XPTR( sem_cxy , &sem_ptr->root );
    152154 
    153155    if( !xlist_is_empty( root_xp ) )   // user error
     
    184186}  // end remote_sem_destroy()
    185187
    186 //////////////////////////////////
     188/////////////////////////////////////
    187189void remote_sem_wait( xptr_t sem_xp )
    188190{
    189191    // get semaphore cluster and local pointer
    190192    cxy_t          sem_cxy = GET_CXY( sem_xp );
    191     remote_sem_t * sem_ptr = (remote_sem_t *)GET_PTR( sem_xp );
     193    remote_sem_t * sem_ptr = GET_PTR( sem_xp );
    192194
    193195    // get lock protecting semaphore     
     
    210212
    211213        // register thread in waiting queue
    212         xptr_t root_xp   = (xptr_t)hal_remote_lwd( XPTR( sem_cxy , &sem_ptr->root ) );
    213         xptr_t thread_xp = XPTR( local_cxy , this );
    214                 xlist_add_last( root_xp , thread_xp );
     214        xptr_t root_xp = XPTR( sem_cxy   , &sem_ptr->root );
     215        xptr_t list_xp = XPTR( local_cxy , &this->wait_list );
     216                xlist_add_last( root_xp , list_xp );
    215217
    216218        // release lock
     
    228230    // get semaphore cluster and local pointer
    229231    cxy_t          sem_cxy = GET_CXY( sem_xp );
    230     remote_sem_t * sem_ptr = (remote_sem_t *)GET_PTR( sem_xp );
     232    remote_sem_t * sem_ptr = GET_PTR( sem_xp );
    231233
    232234    // get lock protecting semaphore
    233235        remote_spinlock_lock( XPTR( sem_cxy , &sem_ptr->lock ) );
    234236 
     237    // get semaphore current value
     238    uint32_t count = hal_remote_lw( XPTR( sem_cxy , &sem_ptr->count ) );
     239
    235240    // get remote pointer on waiting queue root
    236     xptr_t root_xp = (xptr_t)hal_remote_lwd( XPTR( sem_cxy , &sem_ptr->root ) );
     241    xptr_t root_xp = XPTR( sem_cxy , &sem_ptr->root );
    237242 
    238243        if( xlist_is_empty( root_xp ) )   // no waiting thread
    239244    {
    240         // get semaphore current value
    241         uint32_t count = hal_remote_lw( XPTR( sem_cxy , &sem_ptr->count ) );
    242 
    243245        // increment semaphore value
    244246        hal_remote_sw( XPTR( sem_cxy , &sem_ptr->count ) , count + 1 );
     
    251253        // get thread cluster and local poiner
    252254        cxy_t      thread_cxy = GET_CXY( thread_xp );
    253         thread_t * thread_ptr = (thread_t *)GET_PTR( thread_xp );
    254 
    255         // remove the thread from the waiting queue, and unblock
     255        thread_t * thread_ptr = GET_PTR( thread_xp );
     256
     257        // remove this thread from the waiting queue, and unblock it
    256258        xlist_unlink( XPTR( thread_cxy , &thread_ptr->wait_list ) );
    257259                thread_unblock( thread_xp , THREAD_BLOCKED_SEM );
     
    270272    // get semaphore cluster and local pointer
    271273    cxy_t          sem_cxy = GET_CXY( sem_xp );
    272     remote_sem_t * sem_ptr = (remote_sem_t *)GET_PTR( sem_xp );
     274    remote_sem_t * sem_ptr = GET_PTR( sem_xp );
    273275
    274276    *data = hal_remote_lw( XPTR( sem_cxy , &sem_ptr->count ) );
  • trunk/kernel/libk/remote_sem.h

    r23 r457  
    2525#define _SEMAPHORE_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <xlist.h>
    2929#include <remote_spinlock.h>
     
    7777 * This function implements the SEM_INIT operation.
    7878 * It allocates memory for a remote semaphore in reference cluster, using a RPC if required,
    79  * and initializes it, using remote accesses.
     79 * and initializes it, using remote accesses from values defined by the <vaddr> and <value>
     80 * arguments. It uses also a remote access to return the extended pointer on the semaphore
     81 * in the buffer identified by the <buf_xp> argument.
    8082 *********************************************************************************************
    81  * @ vaddr    : semaphore virtual address, used as identifier.
    82  * @ value    : semaphore initial value.
    83  * @ returns 0 if success / returns ENOMEM if error.
     83 * @ vaddr     : [in] semaphore virtual address, used as identifier.
     84 * @ value     : [in] semaphore initial value.
     85 * @ sem_xp_xp : [out] extended pointer on buffer to store extended pointer on semaphore.
     86 * @ returns 0 if success / returns -1 if no memory.
    8487 ********************************************************************************************/
    8588error_t remote_sem_create( intptr_t  vaddr,
    86                            uint32_t  value );
     89                           uint32_t  value,
     90                           xptr_t    sem_xp_xp );
    8791 
    8892/****************************yy***************************************************************
     
    9195 * reference cluster, using a RPC if required.
    9296 *********************************************************************************************
    93  * @ sem_xp   : extended pointer on semaphore.
     97 * @ sem_xp   : [in] extended pointer on semaphore.
    9498 ********************************************************************************************/
    9599void remote_sem_destroy( xptr_t sem_xp );
     
    102106 *    waiting queue, block the thread, and yield.
    103107 *********************************************************************************************
    104  * @ sem_xp   : extended pointer on semaphore.
     108 * @ sem_xp   : [in] extended pointer on semaphore.
    105109 ********************************************************************************************/
    106110void remote_sem_wait( xptr_t sem_xp );
     
    111115 * - If the waiting queue is not empty, it wakes up the first waiting thread.
    112116 *********************************************************************************************
    113  * @ sem_xp   : extended pointer on semaphore.
     117 * @ sem_xp   : [in] extended pointer on semaphore.
    114118 ********************************************************************************************/
    115119void remote_sem_post( xptr_t sem_xp );
     
    119123 * It returns in the <data> buffer the semaphore current value.
    120124 *********************************************************************************************
    121  * @ sem_xp   : extended pointer on semaphore.
    122  * @ data     : [out] returned value.
     125 * @ sem_xp   : [in]  extended pointer on semaphore.
     126 * @ data     : [out] local pointer on buffer for returned value.
    123127 ********************************************************************************************/
    124128void remote_sem_get_value( xptr_t      sem_xp,
  • trunk/kernel/libk/remote_spinlock.c

    r443 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <hal_irqmask.h>
  • trunk/kernel/libk/remote_spinlock.h

    r438 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <xlist.h>
    3030
  • trunk/kernel/libk/rwlock.c

    r438 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_atomic.h>
    2727#include <hal_special.h>
  • trunk/kernel/libk/rwlock.h

    r438 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <list.h>
    3030
  • trunk/kernel/libk/spinlock.c

    r438 r457  
    2424
    2525#include <kernel_config.h>
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727#include <hal_atomic.h>
    2828#include <hal_special.h>
  • trunk/kernel/libk/spinlock.h

    r438 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <list.h>
    3030
  • trunk/kernel/libk/string.c

    r337 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <ctype.h>
    2727#include <string.h>
  • trunk/kernel/libk/string.h

    r323 r457  
    2626#define _STRING_H_
    2727
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929
    3030
  • trunk/kernel/libk/xhtab.c

    r423 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <hal_remote.h>
  • trunk/kernel/libk/xhtab.h

    r204 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <remote_rwlock.h>
    3030#include <xlist.h>
  • trunk/kernel/libk/xlist.h

    r435 r457  
    2626
    2727#include <kernel_config.h>
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <hal_remote.h>
    3030
  • trunk/kernel/mm/kcm.c

    r438 r457  
    2424
    2525#include <kernel_config.h>
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727#include <hal_special.h>
    2828#include <list.h>
  • trunk/kernel/mm/kcm.h

    r437 r457  
    2727
    2828#include <list.h>
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030#include <spinlock.h>
    3131#include <page.h>
  • trunk/kernel/mm/khm.c

    r315 r457  
    2424
    2525#include <kernel_config.h>
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727#include <hal_special.h>
    2828#include <spinlock.h>
  • trunk/kernel/mm/khm.h

    r18 r457  
    2828
    2929#include <kernel_config.h>
    30 #include <hal_types.h>
     30#include <hal_kernel_types.h>
    3131#include <spinlock.h>
    3232
  • trunk/kernel/mm/kmem.c

    r438 r457  
    2525
    2626#include <kernel_config.h>
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <hal_special.h>
    2929#include <printk.h>
  • trunk/kernel/mm/kmem.h

    r188 r457  
    2727#define _KMEM_H_
    2828
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030#include <kcm.h>
    3131
  • trunk/kernel/mm/mapper.c

    r440 r457  
    2424
    2525#include <kernel_config.h>
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727#include <hal_special.h>
    2828#include <hal_uspace.h>
  • trunk/kernel/mm/mapper.h

    r440 r457  
    2626#define _MAPPER_H_
    2727
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <hal_atomic.h>
    3030#include <xlist.h>
  • trunk/kernel/mm/page.c

    r436 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <hal_atomic.h>
  • trunk/kernel/mm/page.h

    r433 r457  
    2727
    2828#include <kernel_config.h>
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030#include <spinlock.h>
    3131#include <list.h>
  • trunk/kernel/mm/ppm.c

    r438 r457  
    2424
    2525#include <kernel_config.h>
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727#include <hal_special.h>
    2828#include <printk.h>
  • trunk/kernel/mm/ppm.h

    r433 r457  
    2626#define _PPM_H_
    2727
    28 #include <hal_types.h>
     28#include <hal_kernel_types.h>
    2929#include <list.h>
    3030#include <spinlock.h>
  • trunk/kernel/mm/vmm.c

    r443 r457  
    2525
    2626#include <kernel_config.h>
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <hal_special.h>
    2929#include <hal_gpt.h>
     
    170170    vmm->stack_mgr.bitmap   = 0;
    171171    vmm->stack_mgr.vpn_base = CONFIG_VMM_STACK_BASE;
     172    spinlock_init( &vmm->stack_mgr.lock );
    172173
    173174    // initialize MMAP allocator
     
    175176    vmm->mmap_mgr.vpn_size        = CONFIG_VMM_STACK_BASE - CONFIG_VMM_HEAP_BASE;
    176177    vmm->mmap_mgr.first_free_vpn  = CONFIG_VMM_HEAP_BASE;
     178    spinlock_init( &vmm->mmap_mgr.lock );
     179
    177180    uint32_t i;
    178181    for( i = 0 ; i < 32 ; i++ ) list_root_init( &vmm->mmap_mgr.zombi_list[i] );
     
    201204    gpt_t * gpt = &vmm->gpt;
    202205
    203     printk("\n***** VSL and GPT for process %x in cluster %x\n\n", process->pid , local_cxy );
     206    printk("\n***** VSL and GPT(%x) for process %x in cluster %x\n\n",
     207    process->vmm.gpt.ptr , process->pid , local_cxy );
    204208
    205209    // get lock protecting the vseg list
  • trunk/kernel/mm/vmm.h

    r440 r457  
    2727#define _VMM_H_
    2828
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030#include <bits.h>
    3131#include <list.h>
  • trunk/kernel/mm/vseg.c

    r453 r457  
    2424 */
    2525
    26 #include <hal_types.h>
     26#include <hal_kernel_types.h>
    2727#include <hal_special.h>
    2828#include <hal_remote.h>
     
    171171    switch (vseg->type)
    172172    {
    173         case VSEG_TYPE_DATA: {
     173        case VSEG_TYPE_DATA:
     174        {
    174175            vseg->cxy = 0xffff;
    175176            break;
    176177        }
    177178        case VSEG_TYPE_CODE:
    178         case VSEG_TYPE_STACK: {
     179        case VSEG_TYPE_STACK:
     180        {
    179181            vseg->cxy = local_cxy;
    180182            break;
     
    182184        case VSEG_TYPE_ANON:
    183185        case VSEG_TYPE_FILE:
    184         case VSEG_TYPE_REMOTE: {
     186        case VSEG_TYPE_REMOTE:
     187        {
    185188            vseg->cxy = (cxy_t) hal_remote_lw( XPTR(cxy, &ptr->cxy) );
    186189            break;
    187190        }
    188         default: {
     191        default:
     192        {
    189193            assert( false, __FUNCTION__, "Illegal vseg type" );
    190194            break;
  • trunk/kernel/mm/vseg.h

    r454 r457  
    2727#define _VSEG_H_
    2828
    29 #include <hal_types.h>
     29#include <hal_kernel_types.h>
    3030#include <spinlock.h>
    3131#include <vfs.h>
  • trunk/kernel/syscalls/shared_include/shared_pthread.h

    r445 r457  
    2929 ******************************************************************************************/
    3030
    31 typedef unsigned int      sem_t;
    3231typedef unsigned int      pthread_cond_t;
    3332typedef unsigned int      pthread_condattr_t;
     
    5655    PT_ATTR_CORE_DEFINED    = 0x0004,  /*! user defined core index in cluster             */
    5756};
    58 
    59 /*******************************************************************************************
    60  * This enum defines the operation mnemonics for operations on POSIX unnamed semaphores.
    61  ******************************************************************************************/
    62 
    63 typedef enum
    64 {
    65         SEM_INIT,
    66         SEM_DESTROY,
    67         SEM_GETVALUE,
    68         SEM_WAIT,
    69         SEM_POST,
    70 }
    71 sem_operation_t;
    7257
    7358/*******************************************************************************************
  • trunk/kernel/syscalls/shared_include/syscalls_numbers.h

    r444 r457  
    6262    SYS_TRACE          = 47,
    6363    SYS_FG             = 48,
    64     SYS_UNDEFINED_49   = 49,   ///
     64    SYS_IS_FG          = 49,
    6565
    6666        SYSCALLS_NR        = 50,
  • trunk/kernel/syscalls/sys_alarm.c

    r23 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <thread.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_barrier.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <errno.h>
  • trunk/kernel/syscalls/sys_chdir.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <chdev.h>
  • trunk/kernel/syscalls/sys_chmod.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <vfs.h>
  • trunk/kernel/syscalls/sys_close.c

    r124 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <vfs.h>
  • trunk/kernel/syscalls/sys_closedir.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <vfs.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_condvar.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <errno.h>
  • trunk/kernel/syscalls/sys_creat.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <vfs.h>
    2626#include <syscalls.h>
  • trunk/kernel/syscalls/sys_display.c

    r450 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <errno.h>
  • trunk/kernel/syscalls/sys_exec.c

    r441 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <errno.h>
     
    152152// It build an exec_info_t structure containing all informations
    153153// required to initialize the new process descriptor and the associated thread.
    154 // It includes the process main() arguments, the environment variables,
     154// It includes the new process main() arguments, the environment variables,
    155155// and the pathname to the new process .elf file.
    156156// It calls the process_exec_get_strings() functions to copy the main() arguments and
    157157// the environment variables from user buffers to the exec_info_t structure, allocate
    158158// and call the process_make_exec() function.
    159 // As it must destroy all parent process copies, and all parent threads in all clusters,
    160 // the process_make_exec() function must be executed in the parent owner cluster,
    161 // and this sys_exec() function uses a RPC to access the owner cluster if required.
     159// As it must destroy all process copies, and all othert threads in all clusters,
     160// the process_make_exec() function must be executed in the owner cluster.
    162161//
    163162// TODO : the args & envs arguments are not supported yet : both must be NULL  [AG]
     
    187186    "args not supported yet\n" );
    188187
    189     // get owner cluster
    190 
    191188    // check pathname length
    192189    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
     
    205202#if DEBUG_SYS_EXEC
    206203uint64_t      tm_start;
    207 uint64_t      tm_end;
    208204tm_start = hal_get_cycles();
    209205if( DEBUG_SYS_EXEC < tm_start )
    210206printk("\n[DBG] %s : thread %x in process %x enter for path <%s> / cycle = %d\n",
    211 __FUNCTION__, this, pid, exec_info.path, (uint32_t)tm_start );
     207__FUNCTION__, this->trdid, pid, exec_info.path, (uint32_t)tm_start );
    212208#endif
    213209
     
    220216#if DEBUG_SYSCALLS_ERROR
    221217printk("\n[ERROR] in %s : thread %x in process %x cannot access args\n",
    222 __FUNCTION__ , this, pid );
     218__FUNCTION__ , this->trdid, pid );
    223219#endif
    224220            this->errno = EINVAL;
     
    235231#if DEBUG_SYCALLS_ERROR
    236232printk("\n[ERROR] in %s : thread %x in process %x cannot access envs\n",
    237 __FUNCTION__ , this, pid );
     233__FUNCTION__ , this->trdid, pid );
    238234#endif
    239235            this->errno = EINVAL;
     
    250246#if DEBUG_SYSCALLS_ERROR
    251247printk("\n[ERROR] in %s : thread %x in process %x cannot create process for <%s>\n",
    252 __FUNCTION__, this, pid, exec_info.path );
     248__FUNCTION__, this->trdid, pid, exec_info.path );
    253249#endif
    254250        this->errno = error;
     
    256252    }
    257253
    258 #if DEBUG_SYS_EXEC
    259 tm_end = hal_get_cycles();
    260 if( DEBUG_SYS_EXEC < tm_end )
    261 printk("\n[DBG] %s : thread %x in process %x exit / cost = %d / cycle %d\n",
    262 __FUNCTION__, this, pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    263 #endif
    264 
    265     // In case of success, this calling thread deschedules, causing suicide,
    266     // because a new process descriptor and its associated main thread
    267     // have been created by the process_make_exec() function, and the
    268     // BLOCKED_GLOBAL & FLAG_REQ_DELETE bits have been set for the calling thread.
    269     sched_yield( "old process suicide in sys_exec()" );
     254    assert( false , __FUNCTION__, "we should not execute this code" );
    270255
    271256    return 0; 
  • trunk/kernel/syscalls/sys_exit.c

    r446 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_irqmask.h>
    2727#include <errno.h>
     
    5959tm_start = hal_get_cycles();
    6060if( DEBUG_SYS_EXIT < tm_start )
    61 printk("\n[DBG] %s : thread %x enter / process %x / status %x / cycle %d\n",
    62 __FUNCTION__ , this, pid , status , (uint32_t)tm_start );
     61printk("\n[DBG] %s : thread %x in process %x enter / status %x / cycle %d\n",
     62__FUNCTION__, this->trdid, process->pid , status , (uint32_t)tm_start );
    6363#endif
    6464
     
    7070#if (DEBUG_SYS_EXIT & 1)
    7171if( DEBUG_SYS_EXIT < tm_start )
    72 printk("\n[DBG] %s : thread %x get owner process %x in cluster %x\n",
    73 __FUNCTION__ , this, owner_ptr, owner_cxy );
     72printk("\n[DBG] %s : thread %x in process %x get owner process %x in cluster %x\n",
     73__FUNCTION__, this->trdid, process->pid, owner_ptr, owner_cxy );
    7474#endif
    7575
    76     // get pointer on the process main thread
     76    // get local pointer on the process main thread
    7777    main_ptr  = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) );
    7878
     
    8484#if (DEBUG_SYS_EXIT & 1)
    8585if( DEBUG_SYS_EXIT < tm_start )
    86 printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n",
    87 __FUNCTION__ , this, parent_ptr, parent_cxy );
     86printk("\n[DBG] %s : thread %x in process %x get parent process %x in cluster %x\n",
     87__FUNCTION__, this->trdid, process->pid, parent_ptr, parent_cxy );
    8888#endif
    8989
     
    9999
    100100#if( DEBUG_SYS_EXIT & 1)
    101 if( tm_start > DEBUG_SYS_EXIT )
    102 printk("\n[DBG] %s : thread %x removed process %x from TXT list\n",
    103 __FUNCTION__ , this, pid );
     101if( DEBUG_SYS_EXIT < tm_start )
     102printk("\n[DBG] %s : thread %x in process %x detached process from TXT\n",
     103__FUNCTION__, this->trdid, process->pid );
    104104#endif
    105105
     
    107107    // but the main thread and this calling thread
    108108    hal_enable_irq( &save_sr );
    109     process_sigaction( pid , DELETE_ALL_THREADS );
     109    process_sigaction( process->pid , DELETE_ALL_THREADS );
    110110    hal_restore_irq( save_sr );
    111111
    112112#if( DEBUG_SYS_EXIT & 1)
    113 if( tm_start > DEBUG_SYS_EXIT )
    114 printk("\n[DBG] %s : thread %x deleted threads for process %x\n",
    115 __FUNCTION__ , this, pid );
     113if( DEBUG_SYS_EXIT < tm_start )
     114printk("\n[DBG] %s : thread %x in process %x deleted all threads but itself\n",
     115__FUNCTION__, this->trdid, process->pid );
    116116#endif
    117117
     
    122122#if( DEBUG_SYS_EXIT & 1)
    123123if( tm_start > DEBUG_SYS_EXIT )
    124 printk("\n[DBG] %s : calling thread %x marked iself for delete in process %x\n",
    125 __FUNCTION__ , this, pid );
     124printk("\n[DBG] %s : thread %x in process %x marked iself for delete\n",
     125__FUNCTION__, this->trdid, process->pid );
    126126#endif
    127127        thread_delete( XPTR( local_cxy , this ) , pid , true );
     
    133133#if( DEBUG_SYS_EXIT & 1)
    134134if( tm_start > DEBUG_SYS_EXIT )
    135 printk("\n[DBG] %s : thread %x blocked main thread for process %x\n",
    136 __FUNCTION__, this , pid );
     135printk("\n[DBG] %s : thread %x in process %x blocked main thread\n",
     136__FUNCTION__, this->trdid, process->pid );
    137137#endif
    138138
     
    144144#if( DEBUG_SYS_EXIT & 1)
    145145if( tm_start > DEBUG_SYS_EXIT )
    146 printk("\n[DBG] %s : thread %x set exit status in process %x / term_state %x\n",
    147 __FUNCTION__ , this, pid, term_state );
     146printk("\n[DBG] %s : thread %x in process %x set exit status %x in owner process\n",
     147__FUNCTION__, this->trdid, process->pid, term_state );
    148148#endif
    149149
    150     // take the children lock and unblock the parent process main thread
     150    // unblock the parent process main thread
    151151    remote_spinlock_lock( children_lock_xp );
    152152    thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
     
    155155#if( DEBUG_SYS_EXIT & 1)
    156156if( tm_start > DEBUG_SYS_EXIT )
    157 printk("\n[DBG] %s : thread %x in cluster %x unblock parent main thread %x in cluster %x\n",
    158 __FUNCTION__ , this, local_cxy, parent_main_ptr, parent_cxy );
     157printk("\n[DBG] %s : thread %x in process %x unblock parent main thread in process %x\n",
     158__FUNCTION__ , this->trdid, process->pid,
     159hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid) ) );
    159160#endif
    160161
     
    164165tm_end = hal_get_cycles();
    165166if( DEBUG_SYS_EXIT < tm_end )
    166 printk("\n[DBG] %s : thread %x exit / process %x / status %x / cost = %d / cycle %d\n",
    167 __FUNCTION__, this, pid, status, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     167printk("\n[DBG] %s : thread %x in process %x exit / status %x / cost = %d / cycle %d\n",
     168__FUNCTION__, this->trdid, process->pid, status,
     169(uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    168170#endif
    169171
  • trunk/kernel/syscalls/sys_fg.c

    r446 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_irqmask.h>
    2727#include <errno.h>
  • trunk/kernel/syscalls/sys_fork.c

    r440 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_context.h>
    2727#include <hal_switch.h>
     
    7070tm_start = hal_get_cycles();
    7171if( DEBUG_SYS_FORK < tm_start )
    72 printk("\n[DBG] %s : parent_thread %x enter / parent_pid %x / cycle =  %d\n",
    73 __FUNCTION__, parent_thread_ptr, parent_pid, (uint32_t)tm_start );
     72printk("\n[DBG] %s : thread %x in process %x enter / cycle =  %d\n",
     73__FUNCTION__, parent_thread_ptr->trdid, parent_pid, (uint32_t)tm_start );
    7474#endif
    7575
     
    106106#if (DEBUG_SYS_FORK & 1 )
    107107if( DEBUG_SYS_FORK < tm_start )
    108 printk("\n[DBG] %s : parent_thread %x selected cluster %x\n",
    109 __FUNCTION__, parent_thread_ptr, child_cxy );
     108printk("\n[DBG] %s : thread %x in process %x selected cluster %x\n",
     109__FUNCTION__, parent_thread_ptr->trdid, parent_pid, child_cxy );
    110110#endif
    111111
     
    165165tm_end = hal_get_cycles();
    166166if( DEBUG_SYS_FORK < tm_end )
    167 printk("\n[DBG] %s : parent_thread %x on cluster %x exit / cost = %d / cycle %d\n",
    168 __FUNCTION__, parent_thread_ptr, parent_cxy, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     167printk("\n[DBG] %s : process %x exit / cost = %d / cycle %d\n",
     168__FUNCTION__, parent_pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    169169#endif
    170 
    171170        return child_pid;
    172171    }
     
    177176tm_end = hal_get_cycles();
    178177if( DEBUG_SYS_FORK < tm_end )
    179 printk("\n[DBG] %s : child_thread %x on cluster %x exit / cost = %d / cycle %d\n",
    180 __FUNCTION__, child_thread_ptr, child_cxy, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     178printk("\n[DBG] %s : process %x exit / cost = %d / cycle %d\n",
     179__FUNCTION__, child_pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    181180#endif
    182 
    183181        return 0;
    184182    }
  • trunk/kernel/syscalls/sys_get_config.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_get_core.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_get_cycle.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_getcwd.c

    r440 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <hal_special.h>
  • trunk/kernel/syscalls/sys_isatty.c

    r438 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <hal_irqmask.h>
  • trunk/kernel/syscalls/sys_kill.c

    r448 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_irqmask.h>
    2727#include <errno.h>
  • trunk/kernel/syscalls/sys_lseek.c

    r23 r457  
    2222
    2323#include <kernel_config.h>
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <errno.h>
  • trunk/kernel/syscalls/sys_mkdir.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <vfs.h>
  • trunk/kernel/syscalls/sys_mkfifo.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_mmap.c

    r440 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <hal_irqmask.h>
  • trunk/kernel/syscalls/sys_munmap.c

    r438 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <shared_syscalls.h>
  • trunk/kernel/syscalls/sys_mutex.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <errno.h>
  • trunk/kernel/syscalls/sys_open.c

    r407 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <errno.h>
  • trunk/kernel/syscalls/sys_opendir.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <thread.h>
    2626#include <process.h>
  • trunk/kernel/syscalls/sys_pipe.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <vfs.h>
    2626#include <process.h>
  • trunk/kernel/syscalls/sys_read.c

    r450 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <hal_irqmask.h>
  • trunk/kernel/syscalls/sys_readdir.c

    r407 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <errno.h>
  • trunk/kernel/syscalls/sys_rmdir.c

    r407 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_sem.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
     26#include <shared_semaphore.h>
    2627#include <errno.h>
    2728#include <thread.h>
     
    3132#include <syscalls.h>
    3233
     34#if DEBUG_SYS_SEM
     35//////////////////////////////////////////////////
     36static char * sys_sem_op_str( uint32_t operation )
     37{
     38        if     ( operation == SEM_INIT     ) return "INIT";
     39        else if( operation == SEM_WAIT     ) return "WAIT";
     40        else if( operation == SEM_POST     ) return "POST";
     41        else if( operation == SEM_GETVALUE ) return "GETVALUE";
     42        else if( operation == SEM_DESTROY  ) return "DESTROY";
     43        else                                 return "undefined";
     44}
     45#endif
     46
    3347//////////////////////////////////
    34 int sys_sem( void         * vaddr,        // semaphore virtual  address
    35              uint32_t       operation,    // requested operation type
    36              uint32_t     * value )       // pointer on in/out argument
     48int sys_sem( void         * vaddr,            // semaphore virtual  address
     49             uint32_t       operation,        // requested operation type
     50             uint32_t       init_value,       // initial value
     51             uint32_t     * current_value )   // pointer on current value buffer
    3752{
    38         uint32_t         data;   
    3953        vseg_t         * vseg;
    4054    error_t          error;
     55    uint32_t         current;     // semaphore current value
     56    xptr_t           sem_xp;      // extended pointer on semaphore
    4157
    4258    thread_t       * this    = CURRENT_THREAD;
    4359    process_t      * process = this->process;
     60
     61#if DEBUG_SYS_SEM
     62uint64_t    tm_start;
     63uint64_t    tm_end;
     64tm_start = hal_get_cycles();
     65if( DEBUG_SYS_SEM < tm_start )
     66printk("\n[DBG] %s : thread %x in process %x enter for %s / cycle %d\n",
     67__FUNCTION__, this->trdid, process->pid, sys_sem_op_str( operation ), (uint32_t)tm_start );
     68#endif
    4469
    4570    // check vaddr in user vspace
     
    4974
    5075#if DEBUG_SYSCALLS_ERROR
    51 printk("\n[ERROR] in %s : unmapped semaphore %x / thread %x / process %x\n",
    52 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
    53 vmm_display( process , false );
    54 #endif
    55         this->errno = EINVAL;
    56         return -1;
    57     }
    58 
    59     // check value in user vspace
    60         error = vmm_get_vseg( process , (intptr_t)value , &vseg );
    61         if( error )
    62     {
    63 
    64 #if DEBUG_SYSCALLS_ERROR
    65 printk("\n[ERROR] in %s : unmapped value %x / thread %x / process %x\n",
     76printk("\n[ERROR] in %s : unmapped semaphore pointer %x / thread %x in process %x\n",
    6677__FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
    6778vmm_display( process , false );
     
    7788            case SEM_INIT:
    7889        {
    79             // get argument
    80                     hal_copy_from_uspace( &data , value , sizeof(uint32_t) );
    81 
    82             // call init function
    83             error = remote_sem_create( (intptr_t)vaddr , data );
     90            // call relevant kernel function to initialize semaphore
     91            error = remote_sem_create( (intptr_t)vaddr ,
     92                                       init_value,
     93                                       XPTR( local_cxy , &sem_xp ) );
    8494
    8595            if ( error )
    8696            {
    87                 printk("\n[ERROR] in %s : cannot create semaphore = %x\n",
    88                        __FUNCTION__ , (intptr_t)value );
    89                 this->errno = error;
    90                 return -1;
    91             }
     97
     98#if DEBUG_SYSCALLS_ERROR
     99printk("\n[ERROR] in %s : cannot create semaphore / thread %x in process %x\n",
     100__FUNCTION__, this->trdid, process->pid );
     101#endif
     102                this->errno = ENOMEM;
     103                return -1;
     104            }
     105
    92106            break;
    93107        }
     
    95109        case SEM_GETVALUE:
    96110        {
    97             // get extended pointer on remote semaphore
    98             xptr_t sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
    99 
    100             if( sem_xp == XPTR_NULL )     // user error
    101             {
    102 
    103 #if DEBUG_SYSCALLS_ERROR
    104 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n",
    105 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid );
    106 #endif
    107                 this->errno = EINVAL;
    108                 return -1;
    109             }
    110             else                          // success
    111             {
    112                 // get semaphore current value
    113                         remote_sem_get_value( sem_xp , &data );
     111            // check current_value buffer in user vspace
     112                error = vmm_get_vseg( process , (intptr_t)current_value , &vseg );
     113            if( error )
     114            {
     115
     116#if DEBUG_SYSCALLS_ERROR
     117printk("\n[ERROR] in %s : unmapped buffer for current value %x / thread %x in process %x\n",
     118__FUNCTION__ , (intptr_t)current_value, this->trdid, process->pid );
     119vmm_display( process , false );
     120#endif
     121                this->errno = EINVAL;
     122                return -1;
     123            }
     124
     125            // get extended pointer on remote semaphore
     126            sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
     127
     128            // check semaphore registered
     129            if( sem_xp == XPTR_NULL )
     130            {
     131
     132#if DEBUG_SYSCALLS_ERROR
     133printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n",
     134__FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
     135#endif
     136                this->errno = EINVAL;
     137                return -1;
     138            }
     139
     140            // call relevant kernel function to get semaphore current value
     141                    remote_sem_get_value( sem_xp , &current );
    114142 
    115                 // return value to user
    116                 hal_copy_to_uspace( value , &data , sizeof(uint32_t) );
    117             }
     143            // return value to user
     144            hal_copy_to_uspace( current_value , &current , sizeof(uint32_t) );
     145
    118146            break;
    119147        }
     
    122150        { 
    123151            // get extended pointer on remote semaphore
    124             xptr_t sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
    125 
    126             if( sem_xp == XPTR_NULL )     // user error
    127             {
    128 
    129 #if DEBUG_SYSCALLS_ERROR
    130 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n",
    131 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid );
    132 #endif
    133                 this->errno = EINVAL;
    134                 return -1;
    135             }
    136             else                          // success
    137             {
    138                 // wait semaphore available
    139                 remote_sem_wait( sem_xp );
    140             }
     152            sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
     153
     154            // check semaphore registered
     155            if( sem_xp == XPTR_NULL )
     156            {
     157
     158#if DEBUG_SYSCALLS_ERROR
     159printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n",
     160__FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
     161#endif
     162                this->errno = EINVAL;
     163                return -1;
     164            }
     165
     166            // call relevant kernel function to wait semaphore available
     167            remote_sem_wait( sem_xp );
     168           
    141169            break;
    142170        }
     
    145173        {
    146174            // get extended pointer on remote semaphore
    147             xptr_t sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
    148 
    149             if( sem_xp == XPTR_NULL )     // user error
    150             {
    151 
    152 #if DEBUG_SYSCALLS_ERROR
    153 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n",
    154 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid );
    155 #endif
    156                 this->errno = EINVAL;
    157                 return -1;
    158             }
    159             else                          // success
    160             {
    161                 // release semaphore
    162                 remote_sem_post( sem_xp );
    163             }
     175            sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
     176
     177            // check semaphore registered
     178            if( sem_xp == XPTR_NULL )
     179            {
     180
     181#if DEBUG_SYSCALLS_ERROR
     182printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n",
     183__FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
     184#endif
     185                this->errno = EINVAL;
     186                return -1;
     187            }
     188
     189            // call relevant kernel function to release semaphore
     190            remote_sem_post( sem_xp );
     191
    164192                        break;
    165193        }
     
    168196        {
    169197            // get extended pointer on remote semaphore
    170             xptr_t sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
    171 
    172             if( sem_xp == XPTR_NULL )     // user error
    173             {
    174 
    175 #if DEBUG_SYSCALLS_ERROR
    176 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n",
    177 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid );
    178 #endif
    179                 this->errno = EINVAL;
    180                 return -1;
    181             }
    182             else                          // success
    183             {
    184                 // destroy semaphore
    185                 remote_sem_destroy( sem_xp );
    186             }
     198            sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );
     199
     200            // check semaphore registered
     201            if( sem_xp == XPTR_NULL )
     202            {
     203
     204#if DEBUG_SYSCALLS_ERROR
     205printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n",
     206__FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
     207#endif
     208                this->errno = EINVAL;
     209                return -1;
     210            }
     211
     212            // destroy semaphore
     213            remote_sem_destroy( sem_xp );
     214
    187215            break;
    188216            }   
     
    190218            default:  // undefined operation                       
    191219        {
    192             printk("\n[PANIC] in %s : illegal operation type\n", __FUNCTION__ );
    193             hal_core_sleep();
     220
     221#if DEBUG_SYSCALLS_ERROR
     222printk("\n[ERROR] in %s : undefined operation type %d / thread %x in process %x\n",
     223__FUNCTION__ , operation, this->trdid, process->pid );
     224#endif
     225            this->errno = EINVAL;
     226            return -1;
    194227        }
    195228        }
    196229
     230    hal_fence();
     231
     232#if DEBUG_SYS_SEM
     233tm_end = hal_get_cycles();
     234if( DEBUG_SYS_SEM < tm_end )
     235{
     236    cxy_t          sem_cxy = GET_CXY( sem_xp );
     237    remote_sem_t * sem_ptr = GET_PTR( sem_xp );
     238    uint32_t       value   = hal_remote_lw( XPTR( sem_cxy , &sem_ptr->count ) );
     239    printk("\n[DBG] %s : thread %x in process %x exit for %s / value %d / cost = %d / cycle %d\n",
     240    __FUNCTION__, this->trdid, process->pid, sys_sem_op_str( operation ), value,
     241    (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     242}
     243#endif
     244
    197245    return 0;
    198246
  • trunk/kernel/syscalls/sys_signal.c

    r435 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <errno.h>
    2727#include <thread.h>
  • trunk/kernel/syscalls/sys_stat.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_thread_cancel.c

    r443 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_irqmask.h>
    2626#include <hal_remote.h>
  • trunk/kernel/syscalls/sys_thread_create.c

    r440 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <printk.h>
  • trunk/kernel/syscalls/sys_thread_detach.c

    r23 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_thread_exit.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_irqmask.h>
    2626#include <thread.h>
  • trunk/kernel/syscalls/sys_thread_join.c

    r438 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <hal_special.h>
  • trunk/kernel/syscalls/sys_thread_wakeup.c

    r438 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <thread.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_thread_yield.c

    r445 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <scheduler.h>
  • trunk/kernel/syscalls/sys_timeofday.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <thread.h>
  • trunk/kernel/syscalls/sys_trace.c

    r443 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <printk.h>
  • trunk/kernel/syscalls/sys_unlink.c

    r407 r457  
    2121 */
    2222
    23 #include <hal_types.h>
     23#include <hal_kernel_types.h>
    2424#include <hal_uspace.h>
    2525#include <vfs.h>
  • trunk/kernel/syscalls/sys_utls.c

    r23 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <errno.h>
    2727#include <thread.h>
  • trunk/kernel/syscalls/sys_wait.c

    r446 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_uspace.h>
    2626#include <hal_irqmask.h>
  • trunk/kernel/syscalls/sys_write.c

    r443 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_uspace.h>
    2727#include <hal_irqmask.h>
  • trunk/kernel/syscalls/syscalls.h

    r445 r457  
    22 * syscalls.h - Kernel side services for syscall handling.
    33 *
    4  * Author     Alain Greiner (2016,2017)
     4 * Author     Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2525#define _SYSCALLS_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <shared_syscalls.h>
    2929
     
    116116 * and the code implementing the operations is in the remore_sem.c file.
    117117 ******************************************************************************************
    118  * @ vaddr     : semaphore virtual address in user space == identifier.
    119  * @ operation : SEM_INIT / SEM_DESTROY / SEM_GETVALUE / SEM_POST / SEM_WAIT.
    120  * @ value     : pointer on in/out argument in user space.
     118 * @ vaddr         : semaphore virtual address in user space == identifier.
     119 * @ operation     : SEM_INIT / SEM_DESTROY / SEM_GETVALUE / SEM_POST / SEM_WAIT.
     120 * @ init_value    : initial semaphore value.
     121 * @ current_value : pointer on buffer for current semaphore value.
    121122 * @ return 0 if success / return -1 if failure.
    122123 *****************************************************************************************/
    123124int sys_sem( void       * vaddr,
    124125             uint32_t     operation,
    125              uint32_t   * value );
     126             uint32_t     init_value,
     127             uint32_t   * current_value );
    126128
    127129/******************************************************************************************
     
    584586
    585587/******************************************************************************************
     588 * [44] TBD
     589 ******************************************************************************************
     590 * @ cxy    : cluster identifier.
     591 * @ lid    : core local index.
     592 * @ return 0 if success / return -1 if failure.
     593 *****************************************************************************************/
     594int sys_place( uint32_t cxy,
     595               uint32_t lid );
     596
     597/******************************************************************************************
    586598 * [45] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition,
    587599 * and deschedule.
     
    624636
    625637/******************************************************************************************
    626  * [49] TBD
    627  ******************************************************************************************
    628  * @ cxy    : cluster identifier.
    629  * @ lid    : core local index.
    630  * @ return 0 if success / return -1 if failure.
    631  *****************************************************************************************/
    632 int sys_place( uint32_t cxy,
    633                uint32_t lid );
     638 * [49] This function returns a non-zero value in the <is_fg> buffer when the process
     639 * identified by the <pid> argument is the current TXT owner.
     640 ******************************************************************************************
     641 * @ pid      : process identifier.
     642 * @ is_fg    : pointer on buffer.
     643 * @ return 0 if success / return -1 if failure.
     644 *****************************************************************************************/
     645int sys_is_fg( pid_t      pid,
     646               uint32_t * is_fg );
    634647
    635648#endif  // _SYSCALLS_H_
  • trunk/libs/libalmosmkh/almosmkh.c

    r445 r457  
    2424#include <almosmkh.h>
    2525#include <hal_user.h>
    26 #include <hal_types.h>
     26#include <hal_shared_types.h>
    2727#include <syscalls_numbers.h>
    2828#include <string.h>
     
    3939    return hal_user_syscall( SYS_FG,
    4040                             (reg_t)pid, 0, 0, 0 );
     41}
     42
     43//////////////////////////////
     44int is_fg( unsigned int   pid,
     45           unsigned int * owner )
     46{
     47    return hal_user_syscall( SYS_IS_FG,
     48                             (reg_t)pid,
     49                             (reg_t)owner, 0, 0 );
    4150}
    4251
     
    224233//////////////////////////////////
    225234int trace( unsigned int active,
    226            unsigned int pid,
     235           unsigned int cxy,
    227236           unsigned int lid )
    228237{
    229238    return hal_user_syscall( SYS_TRACE,
    230239                             (reg_t)active,
    231                              (reg_t)pid,
     240                             (reg_t)cxy,
    232241                             (reg_t)lid, 0 );
    233242}
     
    316325
    317326
    318 ///////////////    non standard debug functions    //////////////////////////
     327///////////////    non standard malloc functions    //////////////////////////
    319328
    320329#define  MALLOC_DEBUG  0
  • trunk/libs/libalmosmkh/almosmkh.h

    r450 r457  
    2626
    2727/***************************************************************************************
    28  * various the user level, ALMOS-MKH specific library. It contains:
     28 * This file defines an user level, ALMOS-MKH specific library, containing:
    2929 * - non standard system calls.
    3030 * - debug functions.
     
    4040/***************************************************************************************
    4141 * This function is used to give the process identified by the <pid> argument the
    42  * exclusive ownership of the attached TXT_RX terminal.
     42 * exclusive ownership of its TXT terminal.
    4343 ***************************************************************************************
    4444 * @ pid        : process identifier.
     
    4646 **************************************************************************************/
    4747int fg( unsigned int pid );
     48
     49/***************************************************************************************
     50 * This function stores in the buffer identified by the <owner> argument a non zero
     51 * value when the process identified by the <pid> argument is currently the exclusive
     52 * owner of its TXT terminal.
     53 ***************************************************************************************
     54 * @ pid        : [in]  process identifier.
     55 * @ owner      : [out] pointer on buffer to store the
     56 * @ returns O if success / returns -1 if process not found.
     57 **************************************************************************************/
     58int is_fg( unsigned int pid,
     59           unsigned int * owner );
    4860
    4961/***************************************************************************************
  • trunk/libs/libpthread/Makefile

    r445 r457  
    99endif
    1010
    11 SRCS = pthread.c
    12 
    13 OBJS = $(addprefix build/, $(SRCS:.c=.o)) \
     11OBJS = build/pthread.o                    \
    1412       $(HAL_ARCH)/build/core/hal_user.o
    1513
     
    3735
    3836headers: build
    39         cp $(SRCS:.c=.h)  build/include/.
     37        cp pthread.h  build/include/.
    4038
    4139
  • trunk/libs/libpthread/pthread.c

    r445 r457  
    11/*
    2  * pthread.c - User leve <pthread> library implementation.
     2 * pthread.c - User level <pthread> library implementation.
    33 *
    44 * Author     Alain Greiner (2016,2017,2018)
     
    2323
    2424#include <hal_user.h>
    25 #include <hal_types.h>
     25#include <hal_shared_types.h>
    2626#include <stdio.h>
    2727#include <stdlib.h>
    2828#include <pthread.h>
     29#include <shared_pthread.h>
    2930#include <almosmkh.h>
    3031#include <syscalls_numbers.h>
  • trunk/libs/libpthread/pthread.h

    r445 r457  
    2525#define _PTHREAD_H_
    2626
     27//////////////////////////////////////////////////////////////////////////////////////////////
     28//             POSIX Threads related functions (including barriers and mutexes)
     29//////////////////////////////////////////////////////////////////////////////////////////////
     30
    2731#include <shared_pthread.h>
    28 
    29 //////////////////////////////////////////////////////////////////////////////////////////////
    30 //             POSIX Threads related functions
    31 //////////////////////////////////////////////////////////////////////////////////////////////
    3232
    3333/*********************************************************************************************
  • trunk/libs/mini-libc/dirent.c

    r449 r457  
    2323
    2424#include <dirent.h>
    25 #include <hal_types.h>
     25#include <hal_shared_types.h>
    2626#include <hal_user.h>
    2727#include <syscalls_numbers.h>
  • trunk/libs/mini-libc/fcntl.c

    r449 r457  
    2323
    2424#include <fcntl.h>
    25 #include <hal_types.h>
     25#include <hal_shared_types.h>
    2626#include <hal_user.h>
    2727#include <syscalls_numbers.h>
  • trunk/libs/mini-libc/mman.c

    r449 r457  
    2323
    2424#include <mman.h>
    25 #include <hal_types.h>
     25#include <hal_shared_types.h>
    2626#include <hal_user.h>
    2727#include <syscalls_numbers.h>
  • trunk/libs/mini-libc/signal.c

    r449 r457  
    11/*
    2  * signal.c - User side signals related syscalls implementation.
     2 * signal.c - User side signals related library implementation.
    33 *
    44 * Author     Alain Greiner (2016,2017,2018)
     
    2323
    2424#include <signal.h>
    25 #include <hal_types.h>
     25#include <hal_shared_types.h>
    2626#include <hal_user.h>
    2727#include <syscalls_numbers.h>
  • trunk/libs/mini-libc/stat.c

    r449 r457  
    11/*
    2  * stat.c - User side file stat related syscalls implementation.
     2 * stat.c - User side file statistics related library implementation.
    33 *
    44 * Author     Alain Greiner (2016,2017,2018)
     
    2424#include <stat.h>
    2525#include <hal_user.h>
    26 #include <hal_types.h>
     26#include <hal_shared_types.h>
    2727#include <syscalls_numbers.h>
    2828
  • trunk/libs/mini-libc/stdio.c

    r445 r457  
    266266    if ( count == -1 )
    267267    {
    268         display_string( "stdlib : xprintf failure" );
     268        display_string( "printf : xprintf failure" );
    269269        return -1;
    270270    }
     
    272272    {
    273273        string[count] = 0;
    274         return write( 1 , &string , count + 1 );
     274        return write( 1 , &string , count );
    275275    }
    276276}
  • trunk/libs/mini-libc/stdlib.c

    r445 r457  
    2323
    2424#include <stdlib.h>
    25 #include <hal_types.h>
     25#include <hal_shared_types.h>
    2626#include <hal_user.h>
     27#include <syscalls_numbers.h>
    2728#include <almosmkh.h>
    2829#include <stdio.h>
    29 #include <syscalls_numbers.h>
    3030
    3131//////////////////////////
  • trunk/libs/mini-libc/time.c

    r449 r457  
    2424#include <time.h>
    2525#include <hal_user.h>
    26 #include <hal_user.h>
    27 #include <hal_types.h>
     26#include <hal_shared_types.h>
    2827#include <syscalls_numbers.h>
    2928
     
    3231                  struct timezone * tz )
    3332{
    34     return hal_user_syscall( SYS_TIMEOFDAY, // TODO SYS_SIGNAL ?
     33    return hal_user_syscall( SYS_TIMEOFDAY,
    3534                             (reg_t)tv,
    3635                             (reg_t)tz, 0, 0 );
  • trunk/libs/mini-libc/unistd.c

    r449 r457  
    2323
    2424#include <unistd.h>
    25 #include <hal_types.h>
     25#include <hal_shared_types.h>
    2626#include <hal_user.h>
    2727#include <syscalls_numbers.h>
  • trunk/libs/mini-libc/wait.c

    r449 r457  
    2424#include <wait.h>
    2525#include <hal_user.h>
    26 #include <hal_types.h>
     26#include <hal_shared_types.h>
    2727#include <syscalls_numbers.h>
    2828
  • trunk/libs/mini-libc/wait.h

    r449 r457  
    3737 * This blocking function returns only when one child process of the calling process
    3838 * changes state (from RUNNING to STOPPED / EXITED / KILLED). It returns the terminating
    39  * child process PID, and set in the <status> buffer the new child process state.
     39 * child process PID, and set in the <status> buffer the terminating child process state.
    4040 *****************************************************************************************
    41  * @ status    : [out] terminating child process state.
     41 * @ status    : [out] pointer on buffer for terminating child process state.
    4242 * @ returns terminating child process pid.
    4343 ****************************************************************************************/
  • trunk/params-hard.mk

    r446 r457  
    55Y_SIZE    = 2
    66NB_PROCS  = 1
    7 NB_TTYS   = 2
     7NB_TTYS   = 3
    88FBF_WIDTH = 128
    99IOC_TYPE  = IOC_BDV
  • trunk/params-soft.mk

    r445 r457  
    4040LIBPTHREAD         = $(LIBPTHREAD_PATH)/build/lib/
    4141LIBPTHREAD_INCLUDE = $(LIBPTHREAD_PATH)/build/include/
     42
     43# define paths for LIBSEMAPHORE
     44LIBSEMAPHORE_PATH    = $(ALMOSMKH_DIR)/libs/libsemaphore
     45LIBSEMAPHORE         = $(LIBSEMAPHORE_PATH)/build/lib/
     46LIBSEMAPHORE_INCLUDE = $(LIBSEMAPHORE_PATH)/build/include/
    4247
    4348# define paths for LIBALMOSMKH
  • trunk/tools/arch_info/arch_info.h

    r6 r457  
    4949 ***************************************************************************************/
    5050
    51 #include <hal_types.h>
     51#include <hal_kernel_types.h>
    5252
    5353#define ARCHINFO_HEADER_SIZE   sizeof(archinfo_header_t)
  • trunk/tools/arch_info/boot_info.h

    r296 r457  
    2525#define _BOOT_INFO_H_
    2626
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <kernel_config.h>
    2929
     
    135135    // kernel segments
    136136
    137     reg_t         kcode_base;                    /*! kernel code base paddr                 */
    138     reg_t         kcode_size;                    /*! kernel code size                       */
    139     reg_t         kdata_base;                    /*! kernel data base paddr                 */
    140     reg_t         kdata_size;                    /*! kernel data size                       */
    141     reg_t         kentry_base;                   /*! kernel entry base paddr                */
    142     reg_t         kentry_size;                   /*! kernel entry size                      */
     137    intptr_t      kcode_base;                    /*! kernel code base paddr                 */
     138    intptr_t      kcode_size;                    /*! kernel code size                       */
     139    intptr_t      kdata_base;                    /*! kernel data base paddr                 */
     140    intptr_t      kdata_size;                    /*! kernel data size                       */
     141    intptr_t      kentry_base;                   /*! kernel entry base paddr                */
     142    intptr_t      kentry_size;                   /*! kernel entry size                      */
    143143}
    144144boot_info_t;
  • trunk/user/idbg/idbg.c

    r450 r457  
    2121    printf( "\n[IDBG] starts at cycle %d\n", (unsigned int)cycle );
    2222
    23 //    idbg();
    24 
    25     exit( 0 );
     23    idbg();
    2624
    2725} // end main()
  • trunk/user/init/init.c

    r445 r457  
    5050    for( i = 1 ; i <  NB_TXT_CHANNELS ; i++ )
    5151    {
     52
     53#if DEBUG_PROCESS_INIT
     54snprintf( string , 64 , "[INIT] start child[%d] creation" , i );
     55display_string( string );
     56#endif
     57
    5258        // INIT process fork process CHILD[i]
    5359        ret_fork = fork();
     
    5662        {
    5763            // INIT display error message 
    58             snprintf( string , 64 , "[INIT] cannot fork child[%d] => suicide" , i );
     64            snprintf( string , 64 , "[INIT ERROR] cannot fork child[%d] => suicide" , i );
    5965            display_string( string );
    6066
     
    7783        else                                      // we are in INIT process
    7884        {
    79              // INIT display CHILD[i] process PID
    80              snprintf( string , 64 , "[INIT] created KSH[%d] / pid = %x", i , ret_fork );
    81              display_string( string );
     85            // INIT display CHILD[i] process PID
     86            snprintf( string , 64 , "[INIT] created KSH[%d] / pid = %x", i , ret_fork );
     87            display_string( string );
    8288        }
    83 
    84         // INIT wait CHILD[i] process deletion before creating KSH[i+1]
    85         // int n;
    86         // for( n = 0 ; n < 100000 ; n++ ) asm volatile ( "nop" );
    87         wait( &status );
    8889    }
    8990 
    9091#if DEBUG_PROCESS_INIT
     92unsigned int  x_size;        // number of clusters in a row
     93unsigned int  y_size;        // number of clusters in a column
     94unsigned int  ncores;        // number of cores per cluster
     95unsigned int  x;             // cluster x coordinate
     96unsigned int  y;             // cluster y coordinate
     97unsigned int  cxy;           // cluster identifier
     98unsigned int  lid;           // core local index
    9199
    92     unsigned int  x_size;        // number of clusters in a row
    93     unsigned int  y_size;        // number of clusters in a column
    94     unsigned int  ncores;        // number of cores per cluster
    95     unsigned int  x;             // cluster x coordinate
    96     unsigned int  y;             // cluster y coordinate
    97     unsigned int  cxy;           // cluster identifier
    98     unsigned int  lid;           // core local index
    99 
    100     // get hardware config
    101     get_config( &x_size , &y_size , &ncores );
     100// get hardware config
     101get_config( &x_size , &y_size , &ncores );
    102102   
    103     // INIT displays processes and threads in all clusters
    104     for( x = 0 ; x < x_size ; x++ )
     103// INIT displays processes and threads in all clusters
     104for( x = 0 ; x < x_size ; x++ )
     105{
     106    for( y = 0 ; y < y_size ; y++ )
    105107    {
    106         for( y = 0 ; y < y_size ; y++ )
    107         {
    108             cxy = CXY_FROM_XY( x , y );
    109             display_cluster_processes( cxy );
    110             for( lid = 0 ; lid < ncores ; lid++ )
    111             {
    112                 display_sched( cxy , lid );
    113             }
     108        cxy = CXY_FROM_XY( x , y );
     109        display_cluster_processes( cxy );
     110        for( lid = 0 ; lid < ncores ; lid++ )
     111        {
     112            display_sched( cxy , lid );
    114113        }
    115114    }
    116 
     115}
    117116#endif
    118117
  • trunk/user/ksh/Makefile

    r445 r457  
    1111OBJS = build/ksh.o
    1212
    13 INCLUDES = -I.                      \
    14            -I$(LIBC_INCLUDE)        \
    15            -I$(LIBPTHREAD_INCLUDE)  \
    16            -I$(LIBALMOSMKH_INCLUDE) \
     13INCLUDES = -I.                       \
     14           -I$(LIBC_INCLUDE)         \
     15           -I$(LIBPTHREAD_INCLUDE)   \
     16           -I$(LIBALMOSMKH_INCLUDE)  \
     17           -I$(LIBSEMAPHORE_INCLUDE) \
    1718           -I$(SHARED_INCLUDE)
    1819
     
    2021
    2122build/ksh.elf : $(OBJS) ksh.ld
    22         $(LD) -o $@ -T ksh.ld $(OBJS) -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -lc -lpthread -lalmosmkh -lpthread -lc
     23        $(LD) -o $@ -T ksh.ld $(OBJS) -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -L$(LIBSEMAPHORE) \
     24    -lc -lpthread -lalmosmkh -lpthread -lsemaphore -lc
    2325        $(DU) -D $@ > $@.txt
    2426
  • trunk/user/ksh/ksh.c

    r446 r457  
    44// Author :  Alain Greiner
    55///////////////////////////////////////////////////////////////////////////////
    6 // This applications implement a minimal shell for ALMOS-MKH.
    7 // This user process contains two POSIX threads:
     6// This application implements a minimal shell for ALMOS-MKH.
     7//
     8// This user KSH process contains two POSIX threads:
    89// - the "main" thread contains the infinite loop implementing
    9 //   the children processes termination monitoring (children processes
    10 //   are created by the <load> command and attached to the KSH TXT terminal).
     10//   the children processes termination monitoring using the wait syscall.
    1111// - the "interactive" thread contains the infinite loop implementing
    1212//   the command interpreter attached to the TXT terminal.
     13//   This "interactive" thread block and deschedules when the KSH process
     14//   loses the TXT terminal ownership. It is reactivated when the KSH
     15//   process returns in background.
     16//
     17// Note: the children processes are created by the <load> command, and are
     18// attached to the same TXT terminal as the KSH process itself.
     19// . A child process can be lauched in foreground: the KSH process loses
     20//   the TXT terminal ownership, that is transfered to the new process.
     21// . A child process can be lauched in background: the KSH process keeps
     22//   the TXT terminal ownership. that is transfered to the new process.
    1323///////////////////////////////////////////////////////////////////////////////
    1424
     
    2030#include <unistd.h>
    2131#include <almosmkh.h>
     32#include <semaphore.h>
    2233
    2334#define CMD_MAX_SIZE   (256)    // max number of characters in one command
     
    2536#define MAX_ARGS           (32)     // max number of arguments in a command
    2637#define FIFO_SIZE      (1024)   // FIFO depth for recursive ls
     38
     39#define KSH_DEBUG      0
    2740
    2841////////////////////////////////////////////////////////////////////////////////
     
    5972unsigned int    ptr;                      // read pointer in log_entries[]
    6073
    61 pthread_attr_t  attr;                     // monitor thread attributes
     74pthread_attr_t  attr;                     // interactive thread attributes
     75
     76sem_t           semaphore;                // block interactive thread when zero
    6277
    6378////////////////////////////////////////////////////////////////////////////////
     
    119134*/
    120135
     136    // release semaphore to get next command
     137    sem_post( &semaphore );
     138
    121139}   // end cmd_cat()
    122140
     
    135153
    136154    printf("  error: not implemented yet\n");
    137 /*
    138         path = argv[1];
    139 
    140         if (chdir(path) == -1)
    141     {
    142                 printf("  error: cannot cd to %s\n", path);
    143         }
    144 */
     155
     156    // release semaphore to get next command
     157    sem_post( &semaphore );
    145158
    146159}   // end cmd_cd()
     
    237250*/
    238251
     252    // release semaphore to get next command
     253    sem_post( &semaphore );
     254
    239255}   // end cmd_cp()
    240256
     
    343359        printf("  usage: display (vmm/sched/process/vfs/chdev/txt) [arg2] [arg3]\n");
    344360    }
     361
     362    // release semaphore to get next command
     363    sem_post( &semaphore );
     364
    345365} // end cmd_display()
    346366
     
    367387                printf("  error: cannot find process %x\n", pid );
    368388        }
     389
     390    // release semaphore to get next command
     391    sem_post( &semaphore );
     392
    369393}  // end cmd_fg()
    370394
     
    385409                printf("\t%s\t : %s\n", cmd[i].name , cmd[i].desc);
    386410        }
     411
     412    // release semaphore to get next command
     413    sem_post( &semaphore );
     414
    387415}   // end cmd_help()
    388416
     
    409437                printf("  error: process %x cannot be killed\n", pid );
    410438        }
     439
     440    // release semaphore to get next command
     441    sem_post( &semaphore );
     442
    411443}   // end cmd_kill()
    412444
     
    419451        char               * pathname;           // path to .elf file
    420452    unsigned int         background;         // background execution if non zero
    421     int                  status;             // new process exit status
    422453
    423454        if( (argc < 2) || (argc > 3) ) 
     
    435466    ksh_pid = getpid();
    436467
     468#if KSH_DEBUG
     469printf("\n[KSH_DEBUG] in %s : ksh PID %x / path %s / background %d\n",
     470__FUNCTION__, ksh_pid, argv[1], background );
     471#endif
     472
    437473    // KSH process fork CHILD process
    438474        ret_fork = fork();
    439475
    440     if ( ret_fork < 0 )          // it is a failure reported to KSH
     476    if ( ret_fork < 0 )     // it is a failure reported to KSH
    441477    {
    442478        printf("  error: ksh process unable to fork\n");
    443479        return;
    444480    }
    445     else if (ret_fork == 0)      // it is the CHILD process
     481    else if (ret_fork == 0) // it is the CHILD process
    446482    {
    447483        // CHILD process exec NEW process
     
    455491        }   
    456492        }
    457     else                        // it is the parent KSH : ret_fork is the new process PID
    458     {
    459         // give back terminal ownership to KSH
    460         // when new process created in background
    461         if( background )   fg( ksh_pid );
    462 
    463         // return to command interpreter
    464         return;
     493    else                    // it is the KSH process : ret_fork is the new process PID
     494    {
     495
     496#if KSH_DEBUG
     497int sem_value;
     498sem_getvalue( &semaphore , &sem_value );
     499printf("\n[KSH_DEBUG] in %s : child PID %x / background %d / sem_value %d\n",
     500ret_fork, background, sem_value  );
     501#endif
     502
     503        if( background )        // child in background =>  KSH keeps TXT ownership
     504        {
     505            // execve() tranfered TXT ownership to child => give it back to KSH
     506            fg( ksh_pid );
     507
     508            // release semaphore to get next command
     509            sem_post( &semaphore );
     510        }
    465511    }
    466512}   // end cmd_load
     
    476522                printf(" - %d\t: %s\n", i, &log_entries[i].buf);
    477523        }
    478 }
     524
     525    // release semaphore to get next command
     526    sem_post( &semaphore );
     527
     528} // end cmd_log()
     529
    479530
    480531////////////////////////////////////////////
     
    509560        closedir(dir);
    510561*/
    511 }
     562
     563    // release semaphore to get next command
     564    sem_post( &semaphore );
     565
     566} // end cmd_ls()
    512567
    513568///////////////////////////////////////////////
     
    525580
    526581    printf("  error: not implemented yet\n");
    527 /*
    528         if ( mkdir( path, 0x700) == -1 )
    529     {
    530                 printf("  error: cannot create directory %s\n", path);
    531         }
    532 */
    533 }
     582
     583    // release semaphore to get next command
     584    sem_post( &semaphore );
     585
     586} // end cmd_mkdir()
    534587
    535588////////////////////////////////////////////
     
    545598    printf("  error: not implemented yet\n");
    546599   
    547 /*
    548         int ret = giet_fat_rename(argv[1], argv[2]);
    549         if (ret < 0)
    550         {
    551                 printf("  error : cannot move %s to %s / err = %d\n", argv[1], argv[2], ret );
    552         }
    553 */
    554 
    555 }
     600    // release semaphore to get next command
     601    sem_post( &semaphore );
     602
     603}  // end cmd_mv
    556604
    557605/////////////////////////////////////////////
     
    574622                printf("%s\n", buf);
    575623        }
    576 }
     624
     625    // release semaphore to get next command
     626    sem_post( &semaphore );
     627
     628}  // end cmd_pwd()
    577629
    578630////////////////////////////////////////////
     
    590642
    591643    printf("  error: not implemented yet\n");
    592 /*
    593         if (remove(path) == -1)
    594     {
    595                 printf("  error: cannot remove %s\n", path);
    596         }
    597 */
    598 
    599 }
     644
     645    // release semaphore to get next command
     646    sem_post( &semaphore );
     647
     648}  // end_cmd_rm()
    600649
    601650///////////////////////////////////////////////
    602651static void cmd_rmdir( int argc , char **argv )
    603652{
     653    // same as cmd_rm()
    604654        cmd_rm(argc, argv);
    605655}
     
    624674        printf("  error: core[%x,%d] not found\n", cxy, lid );
    625675    }
    626 }
     676
     677    // release semaphore to get next command
     678    sem_post( &semaphore );
     679
     680}  // end cmd_trace
    627681
    628682///////////////////////////////////////////////
     
    645699        printf("  error: core[%x,%d] not found\n", cxy, lid );
    646700    }
    647 }
    648 
    649 //////////////////////////////////////////////////////////////////
     701
     702    // release semaphore to get next command
     703    sem_post( &semaphore );
     704
     705}  // end cmd_untrace()
     706
     707///////////////////////////////////////////////////////////////////////////////////
    650708// Array of commands
    651 //////////////////////////////////////////////////////////////////
     709///////////////////////////////////////////////////////////////////////////////////
    652710
    653711ksh_cmd_t cmd[] =
     
    660718        { "load",    "load an user application",                        cmd_load    },
    661719        { "help",    "list available commands",                         cmd_help    },
    662         { "kill",    "kill an application (all threads)",               cmd_kill    },
     720        { "kill",    "kill a process (all threads)",                    cmd_kill    },
    663721        { "log",     "list registered commands",                        cmd_log     },
    664722        { "ls",      "list directory entries",                          cmd_ls      },
     
    674732
    675733////////////////////////////////////////////////////////////////////////////////////
    676 // This function analyses one command (with arguments), execute it, and return.
     734// This function analyses one command (with arguments), executes it, and returns.
    677735////////////////////////////////////////////////////////////////////////////////////
    678 static void parse(char *buf)
     736static void parse( char * buf )
    679737{
    680738        int argc = 0;
     
    717775                }
    718776
    719                 if (!found)
    720         {
    721                         printf("  undefined command <%s>\n", argv[0]);
     777                if (!found)  // undefined command
     778        {
     779                        printf("  error : undefined command <%s>\n", argv[0]);
     780
     781            // release semaphore to get next command
     782            sem_post( &semaphore );
    722783                }
    723784        }
     
    729790        char         c;                                           // read character
    730791        char         buf[CMD_MAX_SIZE];           // buffer for one command
    731         unsigned int count;                               // pointer in buf
     792    unsigned int end_command;             // last character found in a command
     793        unsigned int count;                               // pointer in command buffer
    732794        unsigned int i;                                           // index for loops
     795        unsigned int state;                   // escape sequence state
     796
     797char string[80];
    733798
    734799        enum fsm_states
    735800    {
    736                 NORMAL,
    737                 ESCAPE,
    738                 BRAKET,
     801                NORMAL = 0,
     802                ESCAPE = 1,
     803                BRAKET = 2,
    739804        };
    740805
    741         // initialize command buffer
    742         memset( buf, 0x20 , sizeof(buf) );
    743         count = 0;
    744 
    745         // display first prompt
    746         printf("# ");
    747 
    748         // This lexical analyser writes one command line in the buf buffer.
    749         // It is implemented as a 3 states FSM to handle the following sequences:
     806        // This lexical analyser writes one command line in the command buffer.
     807        // It is implemented as a 3 states FSM to handle the following escape sequences:
    750808        // - ESC [ A : up arrow
    751809        // - ESC [ B : down arrow
     
    757815        // - BRAKET : the wo characters (ESC,[) have been found
    758816
    759         unsigned int state = NORMAL;
    760 
    761 // @@@
    762 parse("load /bin/user/idbg.elf");
    763 // @@@
    764 
     817    // external loop on the commands
     818    // the in teractive thread should not exit this loop
    765819        while (1)
    766820        {
    767                 c = (char)getchar();
    768 
    769         if( c == 0 ) continue;
    770 
    771                 switch (state)
    772                 {
    773                         case NORMAL:
    774                         {
     821            // initialize command buffer
     822            memset( buf, 0x20 , sizeof(buf) );   // TODO useful ?
     823            count = 0;
     824            state = NORMAL;
     825
     826        // block if the KSH process is not the TXT owner
     827        // - if the command is not a "load"
     828        //   the semaphore must be released by the cmd_***()
     829        // - if the command is a load, it depends on
     830        //   the "background" argument
     831        sem_wait( &semaphore );
     832
     833        // display prompt on a new line
     834        printf("\n[ksh] ");
     835 
     836        end_command = 0;
     837
     838        // internal loop on characters in one command
     839        while( end_command == 0 )
     840        {
     841            // get one character from TXT_RX
     842                c = (char)getchar();
     843
     844            if( c == 0 ) continue;
     845
     846                    if( state == NORMAL )  // we are not in an escape sequence
     847                    {
    775848                                if ((c == '\b') || (c == 0x7F))  // backspace => remove one character
    776849                                {
    777                                         if (count > 0) {
    778                                                 printf("\b \b");
    779                                                 count--;
     850                                    if (count > 0)
     851                    {
     852                                        printf("\b \b");
     853                                        count--;
     854                                    }
     855                                }
     856                                else if (c == '\n')                  // new line => end of command
     857                                {
     858                                    if (count > 0)               // analyse & execute command
     859                                    {
     860                                            // complete command with NUL character
     861                                            buf[count] = 0;
     862                        count++;
     863
     864                                        // register command in log arrays
     865                                            strcpy(log_entries[ptw].buf, buf);
     866                                            log_entries[ptw].count = count;
     867                                            ptw = (ptw + 1) % LOG_DEPTH;
     868                                            ptr = ptw;
     869
     870                        // echo character
     871                        putchar( c );
     872
     873                                            // call parser to analyse and execute command
     874                                            parse( buf );
     875                                    }
     876                    else                         // no command registered
     877                    {
     878                        // release semaphore to get next command
     879                        sem_post( &semaphore );
     880                    }
     881
     882                    // exit internal loop on characters
     883                    end_command = 1;
     884                }
     885                            else if (c == '\t')             // tabulation => do nothing
     886                                {
     887                            }
     888                            else if (c == (char)0x1B)       // ESC => start an escape sequence
     889                            {
     890                    state = ESCAPE;
     891                            }
     892                            else                                               // normal character
     893                                {
     894                                    if (count < sizeof(buf) - 1)
     895                                    {
     896                        // register character in command buffer
     897                                            buf[count] = c;
     898                                            count++;
     899
     900                        // echo character
     901                        putchar( c );
    780902                                        }
    781903                                }
    782                                 else if (c == '\n')      // new line => call parser to execute command
    783                                 {
    784                                         if (count > 0)
    785                                         {
    786                                                 // complete command
    787                                                 buf[count] = '\0';
    788 
    789                                                 // register command in log arrays
    790                                                 strcpy(log_entries[ptw].buf, buf);
    791                                                 log_entries[ptw].count = count;
    792                                                 ptw = (ptw + 1) % LOG_DEPTH;
    793                                                 ptr = ptw;
    794 
    795                                                 // execute command
    796                                                 printf("\n");
    797                                                 parse((char *)&buf);
    798 
    799                                                 // reinitialise buffer and display prompt
    800                                                 for ( i = 0 ; i < sizeof(buf) ; i++ ) buf[i] = 0x20;
    801                                                 count = 0;
    802                                                 printf("# ");
    803                                         }
    804                     else
    805                     {
    806                         printf("\n# ");
    807                     }
    808                                 }
    809                                 else if (c == '\t')     // tabulation => do nothing
    810                                 {
    811                                 }
    812                                 else if (c == (char)0x1B)       // ESC => start an escape sequence
    813                                 {
    814                                         state = ESCAPE;
    815                                 }
    816                                 else                                     // register character in command buffer
    817                                 {
    818                                         if (count < sizeof(buf) - 1)
    819                                         {
    820                                                 putchar( c );
    821                                                 buf[count] = c;
    822                                                 count++;
    823                                         }
    824                                 }
    825                                 break;
    826904                        }
    827                         case ESCAPE:
     905                        else if( state == ESCAPE ) 
    828906                        {
    829907                                if (c == '[')           //  valid sequence => continue
     
    835913                                        state = NORMAL;
    836914                                }
    837                                 break;
    838915                        }
    839                         case BRAKET:
     916                        else if( state == BRAKET )
    840917                        {
    841918                                if (c == 'D')   // valid  LEFT sequence => move buf pointer left
     
    900977                                        state = NORMAL;
    901978                                }
    902                                 break;
    903979                        }
    904                 }
    905         }
     980                }  // end internal while loop on characters
     981        }  // end external while loop on commands
    906982}  // end interactive()
    907983
     
    912988    unsigned int lid;             // core identifier for this KSH main thread
    913989    int          status;          // child process termination status
    914     int          pid;             // chils process identifier
     990    int          child_pid;       // child process identifier
     991    int          parent_pid;      // parent process identifier
    915992    pthread_t    trdid;           // kernel allocated index for interactive thread
     993    unsigned int is_owner;        // non-zero if KSH process is TXT owner
    916994
    917995    // initialize log buffer
     
    920998        ptr   = 0;
    921999
     1000    // get KSH process pid and core
     1001    parent_pid = getpid();
    9221002    get_core( &cxy , & lid );
     1003
    9231004        printf( "\n\n~~~ KSH on core[%x,%d] ~~~\n\n", cxy , lid );
     1005
     1006    // initializes the semaphore used to unblock the interactive thread
     1007    sem_init( &semaphore , 0 , 1 );
    9241008
    9251009    // initialize interactive thread attributes
     
    9361020    while( 1 )
    9371021    {
    938         pid = wait( &status );
    939 
    940 #if 0
    941         if     ( WIFEXITED  (status) ) printf("\n[KSH] process %x exited\n" , pid );
    942         else if( WIFSIGNALED(status) ) printf("\n[KSH] process %x killed\n" , pid );
    943         else if( WIFSTOPPED (status) ) printf("\n[KSH] process %x stopped\n", pid );
    944         else                           printf("\n[KSH] process %x strange\n", pid ); 
     1022        // wait children termination
     1023        child_pid = wait( &status );
     1024
     1025#if KSH_DEBUG
     1026if( WIFEXITED  (status) ) printf("\n[KSH] child process %x exited\n" , child_pid );
     1027if( WIFSIGNALED(status) ) printf("\n[KSH] child process %x killed\n" , child_pid );
     1028if( WIFSTOPPED (status) ) printf("\n[KSH] child process %x stopped\n", child_pid );
    9451029#endif
    9461030
     1031        // release semaphore if KSH process is TXT owner, to unblock interactive thread
     1032        is_fg( parent_pid , &is_owner );
     1033        if( is_owner ) sem_post( &semaphore );
     1034
    9471035    }
    9481036}  // end main()
  • trunk/user/sort/sort.c

    r445 r457  
    3232
    3333#define DISPLAY_ARRAY       0
    34 #define INTERACTIVE_MODE    1
     34#define INTERACTIVE_MODE    0
    3535
    3636///////////////////////////////////////////////////////
     
    328328
    329329#if INTERACTIVE_MODE
    330 // idbg();
     330idbg();
    331331#endif
    332332            }
Note: See TracChangeset for help on using the changeset viewer.