Changeset 445


Ignore:
Timestamp:
May 29, 2018, 9:27:23 AM (4 years ago)
Author:
alain
Message:

Restructure the mini_libc.

Location:
trunk
Files:
12 added
4 deleted
34 edited
2 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/hal/generic/hal_user.h

    r407 r445  
    2525#define _HAL_USER_H_
    2626
     27#include <hal_types.h>
    2728
    2829//////////////////////////////////////////////////////////////////////////////////////////
    2930//     User-side, hardware dependant functions API definition.
    3031//
    31 // Any architecture specific implementation must implement this API.
     32//   Any architecture specific implementation must implement this API.
    3233//////////////////////////////////////////////////////////////////////////////////////////
    33 
    3434
    3535/*****************************************************************************************
     
    4545 * @ returned value semantic depends on the syscall index.
    4646 ****************************************************************************************/
    47 int hal_user_syscall( int service_num,
    48                       int arg0,
    49                       int arg1,
    50                       int arg2,
    51                       int arg3 );
     47int hal_user_syscall( reg_t service_num,
     48                      reg_t arg0,
     49                      reg_t arg1,
     50                      reg_t arg2,
     51                      reg_t arg3 );
    5252
    5353/*****************************************************************************************
  • trunk/hal/tsar_mips32/core/hal_gpt.c

    r443 r445  
    22 * hal_gpt.c - implementation of the Generic Page Table API for TSAR-MIPS32
    33 *
    4  * Author   Alain Greiner (2016)
     4 * Author   Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
  • trunk/kernel/kern/printk.c

    r443 r445  
    3030#include <chdev.h>
    3131#include <printk.h>
     32#include <shared_syscalls.h>
    3233
    3334///////////////////////////////////////////////////////////////////////////////////
     
    416417
    417418        // suicide
    418         hal_core_sleep();
     419        sys_exit( EXIT_FAILURE );
    419420    }
    420421}
  • trunk/kernel/kern/process.c

    r443 r445  
    401401uint32_t cycle = (uint32_t)hal_get_cycles();
    402402if( DEBUG_PROCESS_DESTROY )
    403 printk("\n[DBG] %s : thread %x enter in cluster %x / pid %x / process %x / cycle %d\n",
    404 __FUNCTION__ , CURRENT_THREAD , pid , process , cycle );
     403printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
     404__FUNCTION__ , CURRENT_THREAD , pid , local_cxy , cycle );
    405405#endif
    406406
     
    447447cycle = (uint32_t)hal_get_cycles();
    448448if( DEBUG_PROCESS_DESTROY )
    449 printk("\n[DBG] %s : thread %x exit / destroyed process %x (pid = %x) / cycle %d\n",
    450 __FUNCTION__ , CURRENT_THREAD , process, pid, cycle );
     449printk("\n[DBG] %s : thread %x exit / destroyed process %x in cluster %x / cycle %d\n",
     450__FUNCTION__ , CURRENT_THREAD , pid, local_cxy, cycle );
    451451#endif
    452452
     
    13791379    process_txt_detach( XPTR( local_cxy , old_process ) );
    13801380
    1381     // request old_thread destruction => old_process destruction
     1381    // block this old_thread
    13821382    thread_block( XPTR( local_cxy , old_thread ) , THREAD_BLOCKED_GLOBAL );
    1383     hal_atomic_or( &old_thread->flags , THREAD_FLAG_REQ_DELETE );
     1383
     1384    // atomically update old_process descriptor term_state to ask
     1385    // the parent process (wait() function) to delete this old_thread
     1386    hal_atomic_or( &old_process->term_state , PROCESS_TERM_EXIT );
    13841387
    13851388    hal_fence();
  • trunk/kernel/kern/process.h

    r443 r445  
    535535/*********************************************************************************************
    536536 * This function detach a process, identified by the <process_xp> argument,
    537  * from the list of process attached to a given TXT terminal.
     537 * from the list of process attached to a given TXT terminal. It transfer the TXT ownership,
     538 * if the detached process is the TXT owner.
    538539 * The target process descriptor must be in the owner cluster, but the calling thread can
    539540 * be running in any cluster.
  • trunk/kernel/kern/scheduler.c

    r443 r445  
    248248uint32_t cycle = (uint32_t)hal_get_cycles();
    249249if( DEBUG_SCHED_HANDLE_SIGNALS < cycle )
    250 printk("\n[DBG] %s : thread %x in proces %x on core[%x,%d] deleted / cycle %d\n",
     250printk("\n[DBG] %s : thread %x in process %x on core[%x,%d] deleted / cycle %d\n",
    251251__FUNCTION__ , thread->trdid , process->pid , local_cxy , thread->core->lid , cycle );
    252252#endif
  • trunk/kernel/kernel_config.h

    r443 r445  
    9797#define DEBUG_PROCESS_GET_LOCAL_COPY   0
    9898#define DEBUG_PROCESS_INIT_CREATE      0
    99 #define DEBUG_PROCESS_MAKE_EXEC        0
     99#define DEBUG_PROCESS_MAKE_EXEC        1
    100100#define DEBUG_PROCESS_MAKE_FORK        0
    101101#define DEBUG_PROCESS_REFERENCE_INIT   0
    102102#define DEBUG_PROCESS_SIGACTION        0
    103 #define DEBUG_PROCESS_TXT_ATTACH       0
     103#define DEBUG_PROCESS_TXT              2
    104104#define DEBUG_PROCESS_ZERO_CREATE      0
    105105
     
    124124
    125125#define DEBUG_SYS_DISPLAY              0
    126 #define DEBUG_SYS_EXEC                 0
    127 #define DEBUG_SYS_EXIT                 0
     126#define DEBUG_SYS_EXEC                 1
     127#define DEBUG_SYS_EXIT                 1
    128128#define DEBUG_SYS_FG                   0
    129129#define DEBUG_SYS_FORK                 0
    130130#define DEBUG_SYS_GET_CONFIG           0
    131131#define DEBUG_SYS_ISATTY               0
    132 #define DEBUG_SYS_KILL                 0
     132#define DEBUG_SYS_KILL                 2
    133133#define DEBUG_SYS_MMAP                 0
    134134#define DEBUG_SYS_READ                 0
     
    139139#define DEBUG_SYS_THREAD_SLEEP         0
    140140#define DEBUG_SYS_THREAD_WAKEUP        0
     141#define DEBUG_SYS_THREAD_YIELD         2
    141142#define DEBUG_SYS_TRACE                0
    142143#define DEBUG_SYS_WAIT                 0
     
    153154#define DEBUG_THREAD_KERNEL_CREATE     0
    154155#define DEBUG_THREAD_KILL              0
    155 #define DEBUG_THREAD_USER_CREATE       0
     156#define DEBUG_THREAD_USER_CREATE       2
    156157#define DEBUG_THREAD_USER_FORK         0
    157158#define DEBUG_THREAD_BLOCK             0
  • trunk/kernel/syscalls/sys_display.c

    r443 r445  
    244244        chdev_dir_display();
    245245    }
     246    ////////////////////////////////
     247    else if( type == DISPLAY_DQDT )
     248    {
     249        dqdt_display();
     250    }
    246251    ////
    247252    else
  • trunk/kernel/syscalls/sys_exit.c

    r443 r445  
    8686        thread_delete( XPTR( local_cxy , this ) , pid , true );
    8787    }
    88          
     88
    8989    // remove process from TXT list
    9090    process_txt_detach( owner_xp );
  • trunk/kernel/syscalls/sys_thread_yield.c

    r421 r445  
    2222 */
    2323
     24#include <hal_types.h>
     25#include <hal_special.h>
    2426#include <scheduler.h>
     27#include <thread.h>
    2528
    2629int sys_thread_yield()
    2730{
     31 
     32#if DEBUG_SYS_THREAD_YIELD
     33uint64_t     tm_start;
     34uint64_t     tm_end;
     35tm_start = hal_get_cycles();
     36if( DEBUG_SYS_THREAD_YIELD < tm_start )
     37printk("\n[DBG] %s : thread %x deschedule / process %x / cycle %d\n",
     38__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, (uint32_t)tm_start );
     39#endif
     40
     41    // deschedule
    2842        sched_yield("user request");
     43
     44#if DEBUG_SYS_THREAD_YIELD
     45tm_end = hal_get_cycles();
     46if( DEBUG_SYS_THREAD_YIELD < tm_start )
     47printk("\n[DBG] %s : thread %x resume / process %x / cycle %d\n",
     48__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, (uint32_t)tm_end );
     49#endif
     50
    2951        return 0;
    3052}
  • trunk/kernel/syscalls/syscalls.h

    r443 r445  
    195195 ******************************************************************************************
    196196 * @ pathname   : pathname (can be relative or absolute).
    197  * @ flags      : bit vector attributes (see below).
     197 * @ flags      : bit vector attributes (see in shared_fcntl.h file)
    198198 * @ mode       : access rights.
    199199 * @ return file descriptor index in fd_array if success / return -1 if failure.
     
    572572 * - DISPLAY_VFS             : all files registered in the VFS cache.
    573573 * - DISPLAY_CHDEV           : all registered channel devices.
     574 * - DISPLAY_DQDT            : all DQDT nodes.
    574575 ******************************************************************************************
    575576 * type      : [in] type of display
     
    622623int sys_fg( pid_t   pid );
    623624
     625/******************************************************************************************
     626 * [49] TBD
     627 ******************************************************************************************
     628 * @ cxy    : cluster identifier.
     629 * @ lid    : core local index.
     630 * @ return 0 if success / return -1 if failure.
     631 *****************************************************************************************/
    624632int sys_place( uint32_t cxy,
    625633               uint32_t lid );
  • trunk/libs/libalmosmkh/Makefile

    r444 r445  
    11############################################################################
    2 #                  Makefile for the ALMOS-MKH "mini-libc"                  #
     2#                  Makefile for the ALMOS-MKH specific library             #
    33############################################################################
    44
    55-include ../../params-soft.mk
     6
    67ifeq ($(ARCH_NAME),)
    78$(error Please define in ARCH_NAME parameter in params-soft.mk!)
    89endif
    910
    10 SRCS = almos-mkh.c almos-mkh-memory.c
     11SRCS = almosmkh.c
    1112
    1213OBJS = $(addprefix build/, $(SRCS:.c=.o)) \
    1314       $(HAL_ARCH)/build/core/hal_user.o
    1415
    15 INCLUDES = -I. -I$(HAL)/generic -I$(LIBC_INCLUDE) -I$(SHARED_INCLUDE) -I$(LIBPTHREAD_INCLUDE)
     16INCLUDES = -I.                     \
     17           -I$(LIBC_PATH)          \
     18           -I$(LIBPTHREAD_PATH)    \
     19           -I$(SHARED_INCLUDE)     \
     20           -I$(HAL)/generic        \
     21           -I$(HAL_ARCH)/core      \
     22           -I$(KERNEL)
    1623
    17 libs : build/lib/libalmos-mkh.a build/include/almos-mkh.h
     24libs : build/lib/libalmosmkh.a  headers
    1825
    1926build :
     
    2532        $(MAKE) -C $(HAL_ARCH)
    2633
    27 
    28 build/%.o : %.c
     34build/%.o : %.c %.h
    2935        $(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
    3036        $(DU) -D $@ > $@.txt
    3137
    3238headers: build
    33         cp almos-mkh.h build/include/.
    34 build/lib/libalmos-mkh.a: build $(OBJS)
     39        cp $(SRCS:.c=.h)  build/include/.
     40
     41build/lib/libalmosmkh.a: build  $(OBJS)
    3542        $(AR) rc $@ $(OBJS)
    36         ranlib $@
     43        $(RANLIB) $@
    3744
    38 .PHONY = build clean
    39 
     45.PHONY = build clean headers
    4046
    4147clean:
  • trunk/libs/libalmosmkh/almosmkh.c

    r444 r445  
     1/*
     2 * almosmkh.c - User level ALMOS-MKH specific library implementation.
     3 *
     4 * Author     Alain Greiner (2016,2017,2018)
     5 *
     6 * Copyright (c) UPMC Sorbonne Universites
     7 *
     8 * This file is part of ALMOS-MKH.
     9 *
     10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
     11 * under the terms of the GNU General Public License as published by
     12 * the Free Software Foundation; version 2.0 of the License.
     13 *
     14 * ALMOS-MKH is distributed in the hope that it will be useful, but
     15 * WITHOUT ANY WARRANTY; without even the implied warranty of
     16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17 * General Public License for more details.
     18 *
     19 * You should have received a copy of the GNU General Public License
     20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
     21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
     22 */
     23
     24#include <almosmkh.h>
    125#include <hal_user.h>
    2 #include <almos-mkh.h>
     26#include <hal_types.h>
     27#include <syscalls_numbers.h>
     28#include <string.h>
    329#include <stdio.h>
    4 #include <syscalls_numbers.h>
    5 
    6 
    7 #define  reg_t     int
    8 
    9 /////////////     Non standard system calls ////////////////////////////////////
    10 
     30#include <stdlib.h>
     31#include <unistd.h>
     32#include <mman.h>
     33
     34/////////////     Non standard system calls    /////////////////////////////////
    1135
    1236//////////////////////////
     
    3761}
    3862
    39 ////////////////////////////////////
    40 void display_string( char * string )
    41 {
    42     hal_user_syscall( SYS_DISPLAY,
    43                       DISPLAY_STRING,
    44                       (reg_t)string, 0, 0 );
    45 }
    46 
    47 ///////////////////////////////////
    48 int display_vmm( unsigned int cxy, unsigned int pid )
    49 {
    50     return hal_user_syscall( SYS_DISPLAY,
    51                              DISPLAY_VMM,
    52                              (reg_t)pid,
    53                              (reg_t)cxy, 0 );
    54 }
    55 
    56 ////////////////////////////////
    57 int display_sched( unsigned int cxy,
    58                    unsigned int lid )
    59 {
    60     return hal_user_syscall( SYS_DISPLAY,
    61                              DISPLAY_SCHED,
    62                              (reg_t)cxy,
    63                              (reg_t)lid, 0 );
    64 }
    65 
    66 /////////////////////////////////////////////////
    67 int display_cluster_processes( unsigned int cxy )
    68 {
    69     return hal_user_syscall( SYS_DISPLAY,
    70                              DISPLAY_CLUSTER_PROCESSES,
    71                              (reg_t)cxy, 0, 0 );
    72 }
    73 
    74 ///////////////////
    75 int display_chdev()
    76 {
    77     return hal_user_syscall( SYS_DISPLAY,
    78                              DISPLAY_CHDEV, 0, 0, 0 );
    79 }
    80 
    81 /////////////////
    82 int display_vfs()
    83 {
    84     return hal_user_syscall( SYS_DISPLAY,
    85                              DISPLAY_VFS, 0, 0, 0 );
    86 }
    87 
    88 ////////////////////////////////////////////////
    89 int display_txt_processes( unsigned int txt_id )
    90 {
    91     return hal_user_syscall( SYS_DISPLAY,
    92                              DISPLAY_TXT_PROCESSES,
    93                              (reg_t)txt_id, 0, 0 );
    94 }
    95 
    9663///////////////////////////////////////////
    9764int get_cycle( unsigned long long * cycle )
     
    9966    return hal_user_syscall( SYS_GET_CYCLE,
    10067                             (reg_t)cycle, 0, 0, 0 );
    101 }
    102 
    103 //////////////////////////////////
    104 int trace( unsigned int active,
    105            unsigned int pid,
    106            unsigned int lid )
    107 {
    108     return hal_user_syscall( SYS_TRACE,
    109                              (reg_t)active,
    110                              (reg_t)pid,
    111                              (reg_t)lid, 0 );
    11268}
    11369
     
    12076                             (reg_t)value, 0, 0 );
    12177}
    122 
    12378
    12479////////////
     
    207162}  // end getint()
    208163
     164
     165///////////////    non standard debug functions    //////////////////////////
     166
     167////////////////////////////////////
     168void display_string( char * string )
     169{
     170    hal_user_syscall( SYS_DISPLAY,
     171                      DISPLAY_STRING,
     172                      (reg_t)string, 0, 0 );
     173}
     174
     175///////////////////////////////////
     176int display_vmm( unsigned int cxy, unsigned int pid )
     177{
     178    return hal_user_syscall( SYS_DISPLAY,
     179                             DISPLAY_VMM,
     180                             (reg_t)pid,
     181                             (reg_t)cxy, 0 );
     182}
     183
     184////////////////////////////////
     185int display_sched( unsigned int cxy,
     186                   unsigned int lid )
     187{
     188    return hal_user_syscall( SYS_DISPLAY,
     189                             DISPLAY_SCHED,
     190                             (reg_t)cxy,
     191                             (reg_t)lid, 0 );
     192}
     193
     194/////////////////////////////////////////////////
     195int display_cluster_processes( unsigned int cxy )
     196{
     197    return hal_user_syscall( SYS_DISPLAY,
     198                             DISPLAY_CLUSTER_PROCESSES,
     199                             (reg_t)cxy, 0, 0 );
     200}
     201
     202///////////////////
     203int display_chdev()
     204{
     205    return hal_user_syscall( SYS_DISPLAY,
     206                             DISPLAY_CHDEV, 0, 0, 0 );
     207}
     208
     209/////////////////
     210int display_vfs()
     211{
     212    return hal_user_syscall( SYS_DISPLAY,
     213                             DISPLAY_VFS, 0, 0, 0 );
     214}
     215
     216////////////////////////////////////////////////
     217int display_txt_processes( unsigned int txt_id )
     218{
     219    return hal_user_syscall( SYS_DISPLAY,
     220                             DISPLAY_TXT_PROCESSES,
     221                             (reg_t)txt_id, 0, 0 );
     222}
     223
     224//////////////////////////////////
     225int trace( unsigned int active,
     226           unsigned int pid,
     227           unsigned int lid )
     228{
     229    return hal_user_syscall( SYS_TRACE,
     230                             (reg_t)active,
     231                             (reg_t)pid,
     232                             (reg_t)lid, 0 );
     233}
     234
     235//////////////////
     236int display_dqdt()
     237{
     238    return hal_user_syscall( SYS_DISPLAY,
     239                             DISPLAY_DQDT, 0, 0, 0 );
     240}
     241
    209242///////////
    210243void idbg()
     
    283316
    284317
    285 
     318///////////////    non standard debug functions    //////////////////////////
     319
     320#define  MALLOC_DEBUG  0
     321 
     322/////////////////////////////////////////////////////////////////////////////////////////
     323// Global variable defining the allocator array (one per cluster)
     324// This array (about 16 Kbytes ) will be stored in the data segment
     325// of any application linked with this malloc libray.
     326/////////////////////////////////////////////////////////////////////////////////////////
     327
     328malloc_store_t   store[MALLOC_MAX_CLUSTERS];
     329
     330// Macro returning the smallest power of 2 larger or equal to size value
     331
     332#define GET_SIZE_INDEX(size)                (size <= 0x00000001) ? 0  :\
     333                                            (size <= 0x00000002) ? 1  :\
     334                                            (size <= 0x00000004) ? 2  :\
     335                                            (size <= 0x00000008) ? 3  :\
     336                                            (size <= 0x00000010) ? 4  :\
     337                                            (size <= 0x00000020) ? 5  :\
     338                                            (size <= 0x00000040) ? 6  :\
     339                                            (size <= 0x00000080) ? 7  :\
     340                                            (size <= 0x00000100) ? 8  :\
     341                                            (size <= 0x00000200) ? 9  :\
     342                                            (size <= 0x00000400) ? 10 :\
     343                                            (size <= 0x00000800) ? 11 :\
     344                                            (size <= 0x00001000) ? 12 :\
     345                                            (size <= 0x00002000) ? 13 :\
     346                                            (size <= 0x00004000) ? 14 :\
     347                                            (size <= 0x00008000) ? 15 :\
     348                                            (size <= 0x00010000) ? 16 :\
     349                                            (size <= 0x00020000) ? 17 :\
     350                                            (size <= 0x00040000) ? 18 :\
     351                                            (size <= 0x00080000) ? 19 :\
     352                                            (size <= 0x00100000) ? 20 :\
     353                                            (size <= 0x00200000) ? 21 :\
     354                                            (size <= 0x00400000) ? 22 :\
     355                                            (size <= 0x00800000) ? 23 :\
     356                                            (size <= 0x01000000) ? 24 :\
     357                                            (size <= 0x02000000) ? 25 :\
     358                                            (size <= 0x04000000) ? 26 :\
     359                                            (size <= 0x08000000) ? 27 :\
     360                                            (size <= 0x10000000) ? 28 :\
     361                                            (size <= 0x20000000) ? 29 :\
     362                                            (size <= 0x40000000) ? 30 :\
     363                                            (size <= 0x80000000) ? 31 :\
     364                                                                   32
     365
     366////////////////////////////////////////////////////////////////////////////////////////////
     367// This static function display the current state of the allocator in cluster <cxy>.
     368////////////////////////////////////////////////////////////////////////////////////////////
     369
     370#if 0
     371static void display_free_array( unsigned int cxy )
     372{
     373    unsigned int next;
     374    unsigned int id;
     375    unsigned int iter;
     376
     377    printf("\n*****   store[%x] base = %x / size = %x\n",
     378    cxy , store[cxy].store_base, store[cxy].store_size );
     379    for ( id = 0 ; id < 32 ; id++ )
     380    {
     381        next = store[cxy].free[id];
     382        printf(" - free[%d] = " , id );
     383        iter = 0;
     384        while ( next != 0 )
     385        {
     386            printf("%x | ", next );
     387            next = (*(unsigned int*)next);
     388            iter++;
     389        }
     390        printf("0\n");
     391    }
     392}  // end display_free_array()
     393#endif
     394
     395
     396////////////////////////////////////////////////////////////////////i//////////////////////
     397// This static function initialises the store in the cluster identified by the <cxy>
     398// arguments. It is called by the malloc() or remote_malloc when a specific store(x,y)
     399// is accessed for the first time by a remote() or remote_malloc() request.
     400// It uses the mmap( MAP_REMOTE ) syscall to allocate a new vseg mapped in cluster (cxy).
     401////////////////////////////////////////////////////////////////////i//////////////////////
     402// @ cxy        : target cluster identifier (fixed format).
     403// @ store_size : store size (bytes).
     404// # return without setting the initialized field in store(cxy) if failure.
     405////////////////////////////////////////////////////////////////////i//////////////////////
     406static void store_init( unsigned int cxy,
     407                        unsigned int store_size )
     408{
     409    unsigned int   store_base;       // store base address
     410    unsigned int   free_index;       // index in free[array]
     411
     412    unsigned int   alloc_base;       // alloc[] array base
     413    unsigned int   alloc_size;       // alloc[] array size
     414    unsigned int   alloc_index;      // index in alloc[array]
     415
     416    unsigned int   iter;             // iterator
     417
     418#if MALLOC_DEBUG
     419printf("\n[MALLOC] %s : enter for store[%x] / size = %x\n",
     420__FUNCTION__, cxy, store_size );
     421#endif
     422
     423    // get index in free[] array from size
     424    free_index = GET_SIZE_INDEX( store_size );
     425
     426    // check store size power of 2
     427    if( store_size != (1<<free_index) )
     428    {
     429        printf("\n[ERROR] in %s : store[%x] size not power of 2 / size = %x\n",
     430        __FUNCTION__, cxy , store_size );
     431        return;
     432    }
     433
     434    // allocate store in virtual space
     435    void * vadr = mmap( NULL,                     // MAP_FIXED not supported
     436                        store_size,
     437                        PROT_READ | PROT_WRITE,
     438                        MAP_REMOTE| MAP_SHARED,
     439                        cxy,                      // fd is cluster identifier
     440                        0 );                      // offset unused
     441
     442    if( vadr == NULL )
     443    {
     444        printf("\n[ERROR] in %s : cannot mmap store[%x]\n",
     445        __FUNCTION__, cxy );
     446        return;
     447    }
     448
     449    store_base = (unsigned int)vadr;
     450
     451    // check allocated store alignment
     452    if( store_base % store_size )
     453    {
     454        printf("\n[ERROR] in %s : store[%x] not aligned / base = %x / size = %x\n",
     455        __FUNCTION__, cxy , store_base , store_size );
     456        return;
     457    }
     458
     459#if MALLOC_DEBUG
     460printf("\n[MALLOC] %s : mmap done for store[%x] / base = %x\n",
     461__FUNCTION__, cxy, store_base );
     462#endif
     463
     464    // compute size of block containing alloc[] array
     465    alloc_size = store_size / MALLOC_MIN_BLOCK_SIZE;
     466    if ( alloc_size < MALLOC_MIN_BLOCK_SIZE) alloc_size = MALLOC_MIN_BLOCK_SIZE;
     467
     468    // get index for the corresponding block
     469    alloc_index = GET_SIZE_INDEX( alloc_size );
     470
     471    // compute alloc[] array base address
     472    alloc_base = store_base + store_size - alloc_size;
     473
     474    // reset the free[] array
     475    for ( iter = 0 ; iter < 32 ; iter++ )
     476    {
     477        store[cxy].free[iter] = 0;
     478    }
     479
     480    // DEPRECATED: we don't reset the alloc_size array
     481    // because we don't want to allocate the physical memory
     482    // when the heap is created  [AG]
     483    // memset( (void *)alloc_base , 0 , alloc_size );
     484 
     485    // split the store into various sizes blocks,
     486    // initializes the free[] array and NEXT pointers
     487    // base is the block base address
     488    unsigned int   base = store_base;
     489    unsigned int * ptr;
     490    for ( iter = free_index-1 ; iter >= alloc_index ; iter-- )
     491    {
     492        store[cxy].free[iter] = base;
     493        ptr = (unsigned int*)base;
     494        *ptr = 0;
     495        base = base + (1<<iter);
     496    }
     497
     498    // initialize store mutex
     499    if( pthread_mutex_init( &store[cxy].mutex , NULL ) )
     500    {
     501        printf("\n[ERROR] in %s : cannot initialize mutex for store[%x]\n",
     502        __FUNCTION__, cxy );
     503        return;
     504    }
     505
     506    store[cxy].cxy         = cxy;
     507    store[cxy].store_base  = store_base;
     508    store[cxy].store_size  = store_size;
     509    store[cxy].alloc_size  = alloc_size;
     510    store[cxy].alloc_base  = alloc_base;
     511    store[cxy].initialized = MALLOC_INITIALIZED;
     512
     513
     514#if MALLOC_DEBUG
     515printf("\n[MALLOC] %s : completes store[%x] initialisation\n",
     516__FUNCTION__, cxy );
     517
     518display_free_array( cxy );
     519#endif
     520
     521}  // end store_init()
     522
     523////////////////////////////////////////////////////////
     524static unsigned int split_block( malloc_store_t * store,
     525                                 unsigned int     vaddr,
     526                                 unsigned int     searched_index,
     527                                 unsigned int     requested_index )
     528{
     529    // push the upper half block into free[searched_index-1]
     530    unsigned int* new            = (unsigned int*)(vaddr + (1<<(searched_index-1)));
     531    *new                         = store->free[searched_index-1];
     532    store->free[searched_index-1] = (unsigned int)new;
     533       
     534    if ( searched_index == requested_index + 1 )  // terminal case: return lower half block
     535    {
     536        return vaddr;
     537    }
     538    else            // non terminal case : lower half block must be split again
     539    {                               
     540        return split_block( store, vaddr, searched_index-1, requested_index );
     541    }
     542} // end split_block()
     543
     544//////////////////////////////////////////////////////
     545static unsigned int get_block( malloc_store_t * store,
     546                               unsigned int     searched_index,
     547                               unsigned int     requested_index )
     548{
     549    // test terminal case
     550    if ( (1<<searched_index) > store->store_size )  // failure : return a NULL value
     551    {
     552        return 0;
     553    }
     554    else                            // search a block in free[searched_index]
     555    {
     556        unsigned int vaddr = store->free[searched_index];
     557        if ( vaddr == 0 )     // block not found : search in free[searched_index+1]
     558        {
     559            return get_block( store, searched_index+1, requested_index );
     560        }
     561        else                // block found : pop it from free[searched_index]
     562        {
     563            // pop the block from free[searched_index]
     564            unsigned int next = *((unsigned int*)vaddr);
     565            store->free[searched_index] = next;
     566           
     567            // test if the block must be split
     568            if ( searched_index == requested_index )  // no split required
     569            {
     570                return vaddr;
     571            }
     572            else                                      // split is required
     573            {
     574                return split_block( store, vaddr, searched_index, requested_index );
     575            }
     576        }
     577    }
     578} // end get_block()
     579
     580////////////////////////////////////////
     581void * remote_malloc( unsigned int size,
     582                      unsigned int cxy )
     583{
     584
     585#if MALLOC_DEBUG
     586printf("\n[MALLOC] %s : enter for size = %x / cxy = %x\n",
     587__FUNCTION__ , size , cxy );
     588#endif
     589
     590    // check arguments
     591    if( size == 0 )
     592    {
     593        printf("\n[ERROR] in %s : requested size = 0 \n",
     594        __FUNCTION__ );
     595        return NULL;
     596    }
     597    if( cxy >= MALLOC_MAX_CLUSTERS )
     598    {
     599        printf("\n[ERROR] in %s : illegal cluster %x\n",
     600        __FUNCTION__ , cxy );
     601        return NULL;
     602    }
     603
     604    // initializes target store if required
     605    if( store[cxy].initialized != MALLOC_INITIALIZED )
     606    {
     607        store_init( cxy , MALLOC_LOCAL_STORE_SIZE );
     608
     609        if( store[cxy].initialized != MALLOC_INITIALIZED )
     610        {
     611            printf("\n[ERROR] in %s : cannot allocate store in cluster %x\n",
     612            __FUNCTION__ , cxy );
     613            return NULL;
     614        }
     615    }
     616
     617    // normalize size
     618    if ( size < MALLOC_MIN_BLOCK_SIZE ) size = MALLOC_MIN_BLOCK_SIZE;
     619
     620    // compute requested_index for the free[] array
     621    unsigned int requested_index = GET_SIZE_INDEX( size );
     622
     623    // take the lock protecting access to store[cxy]
     624    pthread_mutex_lock( &store[cxy].mutex );
     625
     626    // call the recursive function get_block
     627    unsigned int base = get_block( &store[cxy],
     628                                   requested_index,
     629                                   requested_index );
     630
     631    // check block found
     632    if (base == 0)
     633    {
     634        pthread_mutex_unlock( &store[cxy].mutex );
     635        printf("\n[ERROR] in %s : no more space in cluster %x\n",
     636        __FUNCTION__ , cxy );
     637        return NULL;
     638    }
     639
     640    // compute pointer in alloc[] array
     641    unsigned        offset = (base - store[cxy].store_base) / MALLOC_MIN_BLOCK_SIZE;
     642    unsigned char * ptr    = (unsigned char*)(store[cxy].alloc_base + offset);
     643
     644    // DEPRECATED : we don't check the alloc[] array,
     645    // because it has not been initialised, to avoid
     646    // physical memory allocation at heap creation [AG]
     647    // if ( *ptr != 0 )
     648    // {
     649    //    pthread_mutex_unlock( &store[cxy].mutex );
     650    //    printf("\n[PANIC] in %s : allocate an already allocated block...\n",
     651    //    __FUNCTION__ );
     652    //    return NULL;
     653    // }
     654
     655    // update alloc_array
     656    *ptr = requested_index;
     657
     658    // release the lock
     659    pthread_mutex_unlock( &store[cxy].mutex );
     660 
     661#if MALLOC_DEBUG
     662printf("\n[MALLOC] %s : exit / base = %x / size = %x / from store[%x]\n",
     663__FUNCTION__, base , size , cxy );
     664#endif
     665
     666    return (void*) base;
     667
     668} // end remote_malloc()
     669
     670
     671
     672//////////////////////////////////////////
     673void * remote_calloc ( unsigned int count,
     674                       unsigned int size,
     675                       unsigned int cxy )
     676{
     677    void * ptr = remote_malloc( count * size , cxy );
     678    memset( ptr , 0 , count * size );
     679    return ptr;
     680}
     681
     682//////////////////////////////////
     683void * remote_realloc( void * ptr,
     684                       unsigned int size,
     685                       unsigned int cxy )
     686{
     687    // simple allocation when (ptr == NULL)
     688    if( ptr == NULL )
     689    {
     690        return remote_malloc( size , cxy );
     691    }
     692
     693    // simple free when (size == 0)
     694    if( size == 0 )
     695    {
     696        remote_free( ptr , cxy );
     697        return NULL;
     698    }
     699
     700    // check cxy and ptr in general case
     701    if( cxy >= MALLOC_MAX_CLUSTERS )
     702    {
     703        printf("\n[ERROR] in %s : illegal cluster index %x\n",
     704        __FUNCTION__ , cxy );
     705        return NULL;
     706    }
     707
     708    unsigned int base = (unsigned int)ptr;
     709
     710    if( (base < store[cxy].store_base) ||
     711        (base >= (store[cxy].store_base + store[cxy].store_size)) )
     712    {
     713        printf("\n[ERROR] in %s : illegal pointer = %x\n",
     714        __FUNCTION__, ptr );
     715        return NULL;
     716    }
     717 
     718    // compute index in free[] array
     719    int index = (base - store[cxy].store_base) / MALLOC_MIN_BLOCK_SIZE;
     720
     721    // compute old size
     722    char * pchar = (char *) (store[cxy].alloc_base + index);
     723    int old_size = 1 << ((int) *pchar);
     724
     725    // allocate a new block
     726    void * new_ptr = remote_malloc( size , cxy );
     727
     728    // save old data to new block
     729    int min_size = (size < old_size) ? size : old_size;
     730    memcpy( new_ptr, ptr, min_size );
     731
     732    // release old block
     733    remote_free( ptr , cxy );
     734
     735    return new_ptr;
     736}
     737
     738//////////////////////////////////////////////////////
     739static void update_free_array( malloc_store_t * store,
     740                               unsigned int     base,
     741                               unsigned int     size_index )
     742{
     743    // This recursive function try to merge the released block
     744    // with the companion block if this companion block is free.
     745    // This companion has the same size, and almost the same address
     746    // (only one address bit is different)
     747    // - If the companion is not in free[size_index],
     748    //   the released block is pushed in free[size_index].
     749    // - If the companion is found, it is evicted from free[size_index]
     750    //   and the merged bloc is pushed in the free[size_index+1].
     751
     752
     753    // compute released block size
     754    unsigned int size = 1<<size_index;
     755
     756    // compute companion block and merged block base addresses
     757    unsigned int companion_base; 
     758    unsigned int merged_base; 
     759
     760    if ( (base & size) == 0 )   // the released block is aligned on (2*size)
     761    {
     762        companion_base  = base + size;
     763        merged_base     = base;
     764    }
     765    else
     766    {
     767        companion_base  = base - size;
     768        merged_base     = base - size;
     769    }
     770
     771    // scan all blocks in free[size_index]
     772    // the iter & prev variables are actually addresses
     773    unsigned int  found = 0;
     774    unsigned int  iter  = store->free[size_index];
     775    unsigned int  prev  = (unsigned int)&store->free[size_index];
     776    while ( iter )
     777    {
     778        if ( iter == companion_base )
     779        {
     780            found = 1;
     781            break;
     782        }
     783        prev = iter;
     784        iter = *(unsigned int*)iter;
     785    }
     786
     787    if ( found == 0 )  // Companion not found => push in free[size_index] 
     788    {
     789        *(unsigned int*)base   = store->free[size_index];
     790        store->free[size_index] = base;
     791    }
     792    else               // Companion found : merge
     793    {
     794        // evict the searched block from free[size_index]
     795        *(unsigned int*)prev = *(unsigned int*)iter;
     796
     797        // call the update_free() function for free[size_index+1]
     798        update_free_array( store, merged_base , size_index+1 );
     799    }
     800}  // end update_free_array()
     801
     802////////////////////////////////////
     803void remote_free( void        * ptr,
     804                  unsigned int  cxy )
     805{
     806
     807#if MALLOC_DEBUG
     808printf("\n[MALLOC] %s : enter for block = %x / cxy = %x\n",
     809__FUNCTION__, ptr, cxy );
     810#endif
     811
     812    unsigned int base = (unsigned int)ptr;
     813
     814    // check cxy value
     815    if( cxy >= MALLOC_MAX_CLUSTERS )
     816    {
     817        printf("\n[ERROR] in %s : illegal cluster index %x\n",
     818        __FUNCTION__ , cxy );
     819        return;
     820    }
     821
     822    // check ptr value
     823    if( (base < store[cxy].store_base) ||
     824        (base >= (store[cxy].store_base + store[cxy].store_size)) )
     825    {
     826        printf("\n[ERROR] in %s : illegal pointer for released block = %x\n",
     827        __FUNCTION__, ptr );
     828        return;
     829    }
     830 
     831    // get the lock protecting store[cxy]
     832    pthread_mutex_lock( &store[cxy].mutex );
     833
     834    // compute released block index in alloc[] array
     835    unsigned index = (base - store[cxy].store_base ) / MALLOC_MIN_BLOCK_SIZE;
     836 
     837    // get the released block size_index
     838    unsigned char* pchar      = (unsigned char*)(store[cxy].alloc_base + index);
     839    unsigned int   size_index = (unsigned int)*pchar;
     840
     841    // check block is allocated
     842    if ( size_index == 0 )
     843    {
     844        pthread_mutex_unlock( &store[cxy].mutex );
     845        printf("\n[ERROR] in %s : released block not allocated / ptr = %x\n",
     846        __FUNCTION__, ptr );
     847        return;
     848    }
     849
     850    // check released block alignment
     851    if ( base % (1 << size_index) )
     852    {
     853        pthread_mutex_unlock( &store[cxy].mutex );
     854        printf("\n[ERROR] in %s : released block not aligned / ptr = %x\n",
     855        __FUNCTION__, ptr );
     856        return;
     857    }
     858
     859    // reset the alloc[index] entry
     860    *pchar = 0;
     861
     862    // call the recursive function update_free_array()
     863    update_free_array( &store[cxy], base, size_index );
     864
     865    // release the lock
     866    pthread_mutex_unlock( &store[cxy].mutex );
     867
     868#if MALLOC_DEBUG
     869printf("\n[MALLOC] %s : conmpletes for block = %x / cxy = %x\n",
     870__FUNCTION__, ptr, cxy );
     871#endif
     872
     873} // end remote_free()
     874
     875// Local Variables:
     876// tab-width: 4
     877// c-basic-offset: 4
     878// c-file-offsets:((innamespace . 0)(inline-open . 0))
     879// indent-tabs-mode: nil
     880// End:
     881// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     882
     883
     884
  • trunk/libs/libalmosmkh/almosmkh.h

    r444 r445  
     1/*
     2 * almosmkh.h - User level ALMOS-MKH specific library definition.
     3 *
     4 * Author     Alain Greiner (2016,2017,2018)
     5 *
     6 * Copyright (c) UPMC Sorbonne Universites
     7 *
     8 * This file is part of ALMOS-MKH.
     9 *
     10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
     11 * under the terms of the GNU General Public License as published by
     12 * the Free Software Foundation; version 2.0 of the License.
     13 *
     14 * ALMOS-MKH is distributed in the hope that it will be useful, but
     15 * WITHOUT ANY WARRANTY; without even the implied warranty of
     16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17 * General Public License for more details.
     18 *
     19 * You should have received a copy of the GNU General Public License
     20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
     21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
     22 */
     23
    124#ifndef _LIBALMOSMKH_H_
    225#define _LIBALMOSMKH_H_
    326
    4 #include <almos-mkh/almos-mkh.h>
     27/***************************************************************************************
     28 * various the user level, ALMOS-MKH specific library. It contains:
     29 * - non standard system calls.
     30 * - debug functions.
     31 * - remote malloc extensions.
     32 **************************************************************************************/
     33
    534#include <pthread.h>
    6 
    7 /****************** Non standard (ALMOS_MKH specific) system calls **********************/
    8 
    9 
    10 /*****************************************************************************************
     35#include <shared_almos.h>
     36
     37/****************** Non standard (ALMOS_MKH specific) system calls ********************/
     38
     39
     40/***************************************************************************************
    1141 * This function is used to give the process identified by the <pid> argument the
    1242 * exclusive ownership of the attached TXT_RX terminal.
    13  *****************************************************************************************
     43 ***************************************************************************************
    1444 * @ pid        : process identifier.
    1545 * @ returns O if success / returns -1 if process not found.
    16  ****************************************************************************************/
     46 **************************************************************************************/
    1747int fg( unsigned int pid );
    1848
     
    4979
    5080/***************************************************************************************
     81 * This function implement the operations related to User Thread Local Storage.
     82 ***************************************************************************************
     83 * @ operation  : UTLS operation type as defined in "shared_sycalls.h" file.
     84 * @ value      : argument value for the UTLS_SET operation.
     85 * @ return value for the UTLS_GET and UTLS_GET_ERRNO / return -1 if failure.
     86 **************************************************************************************/
     87int utls( unsigned int operation,
     88          unsigned int value );
     89
     90/***************************************************************************************
     91 * This function returns a positive integer fom the standard "stdin" stream.
     92 ***************************************************************************************
     93 * returns the integer value if success / returns -1 if failure.
     94 **************************************************************************************/
     95int getint();
     96
     97
     98/***************** Non standard (ALMOS-MKH specific) debug functions ******************/
     99
     100
     101/***************************************************************************************
    51102 * This debug function displays on the kernel terminal TXT0
    52103 * the thread / process / core identifiers, the current cycle, plus a user defined
     
    91142/***************************************************************************************
    92143 * This debug function displays on the kernel terminal TXT0
     144 * the list of processes attached to a given TXT channel.
     145 * It can be called by any thread running in any cluster.
     146 ***************************************************************************************
     147 * @ txt_id   : [in] TXT terminal indes.
     148 * @ return 0 if success / return -1 if illegal argument.
     149 **************************************************************************************/
     150int display_txt_processes( unsigned int txt_id );
     151
     152/***************************************************************************************
     153 * This debug function displays on the kernel terminal TXT0
    93154 * the list of channel devices available in the architecture.
    94155 * It can be called by any thread running in any cluster.
     
    108169
    109170/***************************************************************************************
    110  * This debug function displays on the kernel terminal TXT0
    111  * the list of processes attached to a given TXT channel.
    112  * It can be called by any thread running in any cluster.
    113  ***************************************************************************************
    114  * @ return always 0.
    115  **************************************************************************************/
    116 int display_txt_processes( unsigned int txt_id );
     171 * This debug function displays on the kernel terminal TXT0 the current DQDT state.
     172 * It can be called by any thread running in any cluster.
     173 ***************************************************************************************
     174 * @ return always 0.
     175 **************************************************************************************/
     176int display_dqdt();
    117177
    118178/*****************************************************************************************
     
    126186* @ returns O if success / returns -1 if illegal arguments.
    127187****************************************************************************************/
    128 
    129188int trace( unsigned int active,
    130189           unsigned int pid,
    131190           unsigned int trdid );
    132191
    133 /*****************************************************************************************
    134  * This function implement the operations related to User Thread Local Storage.
    135  *****************************************************************************************
    136  * @ operation  : UTLS operation type as defined in "shared_sycalls.h" file.
    137  * @ value      : argument value for the UTLS_SET operation.
    138  * @ return value for the UTLS_GET and UTLS_GET_ERRNO / return -1 if failure.
    139  ****************************************************************************************/
    140 int utls( unsigned int operation,
    141           unsigned int value );
    142 
    143 /*********************************************************************************************
    144  * This function returns a positive integer fom the standard "stdin" stream.
    145  *********************************************************************************************
    146  * returns the integer value if success / returns -1 if failure.
    147  ********************************************************************************************/
    148 int getint();
    149 
    150 
    151 /////// Non-standard memory operations ////////////
    152 ////////////////////////////////////////////////////////////////////////////////
     192/****************************************************************************************
     193 * This blocking function implements an user-level interactive debugger that can be
     194 * introduced in any user application to display various kernel distributed structures.
     195 * The supported commands are:
     196 * - p (cxy)     : display all processes descriptors in a given cluster.
     197 * - s (cxy,lid) : display all threads attached to a given core in a given cluster.
     198 * - v (cxy)     : display the calling process VMM in a given cluster.
     199 * - t (tid)     : display all owner process descriptors attached to a TXT terminal.
     200 * - x           : force the calling process to exit.
     201 * - c           : continue calling process execution.
     202 * - h           : list the supported commands
     203 ***************************************************************************************/
     204void idbg();
     205
     206
     207/****************** Non standard (ALMOS-MKH specific) malloc operations  ***************/
     208
     209/////////////////////////////////////////////////////////////////////////////////////////
    153210// General principles:
    154211// - In user space the HEAP zone spread between the ELF zone and the STACK zone,
     
    168225//        We should introduce the possibility to dynamically allocate
    169226//        several vsegs in each cluster, using several mmap when required.
    170 ////////////////////////////////////////////////////////////////////////////////
     227/////////////////////////////////////////////////////////////////////////////////////////
    171228// Free blocks organisation in each cluster :
    172229// - All free blocks have a size that is a power of 2, larger or equal
     
    179236// - The pointers on the first free block for each size are stored in an
    180237//   array of pointers free[32] in the storage(x,y) descriptor.
    181 ////////////////////////////////////////////////////////////////////////////////
     238/////////////////////////////////////////////////////////////////////////////////////////
    182239// Allocation policy:
    183240// - The block size required by the user can be any value, but the allocated
     
    200257//   If the vseg is aligned (the vseg base is a multiple of the
    201258//   vseg size), all allocated blocks are aligned on the actual_size.
    202 ////////////////////////////////////////////////////////////////////////////////
     259/////////////////////////////////////////////////////////////////////////////////////////
    203260// Free policy:
    204261// - Each allocated block is registered in an alloc[] array of unsigned char.
     
    213270// - The alloc[] array is stored at the end of heap segment. This consume
    214271//   (1 / MALLOC_MIN_BLOCK_SIZE) of the total storage capacity.
    215 ////////////////////////////////////////////////////////////////////////////////
     272/////////////////////////////////////////////////////////////////////////////////////////
    216273
    217274
     
    221278#define MALLOC_MAX_CLUSTERS        0x100        // 256 clusters
    222279
    223 ////////////////////////////////////////////////////////////////////////////////
    224 // store(x,y) descriptor (one per cluster)
    225 ////////////////////////////////////////////////////////////////////////////////
     280/////////////////////////////////////////////////////////////////////////////////////////
     281//               store(x,y) descriptor (one per cluster)
     282/////////////////////////////////////////////////////////////////////////////////////////
    226283
    227284typedef struct malloc_store_s
    228285{
    229     pthread_mutex_t mutex;           // lock protecting exclusive access
     286    pthread_mutex_t mutex;           // lock protecting exclusive access to local heap
    230287    unsigned int    initialized;     // initialised when value == MALLOC_INITIALIZED
    231288    unsigned int    cxy;             // cluster identifier 
     
    276333                       unsigned int  size,
    277334                       unsigned int  cxy );
     335
    278336/*****************************************************************************************
    279337 * This function allocates enough space for <count> objects that are <size> bytes
     
    290348                      unsigned int cxy );
    291349
    292 /*********************************************************************************************
    293  * This blocking function implements an user-level interactive debugger that can be
    294  * introduced in any user application to display various kernel distributed structures
    295  * related to the calling process. The supported commands are:
    296  * - p (cxy)     : display all processes descriptors in a given cluster.
    297  * - s (cxy,lid) : display all threads attached to a given core in a given cluster.
    298  * - v (cxy)     : display the calling process VMM in a given cluster.
    299  * - t (tid)     : display all owner process descriptors attached to a given TXT terminal.
    300  * - x           : force the calling process to exit.
    301  * - c           : continue calling process execution.
    302  *********************************************************************************************
    303  * @ return an integer value between 0 and RAND_MAX.
    304  ********************************************************************************************/
    305 void idbg();
    306 
    307350#endif /* _LIBALMOSMKH_H_ */
    308351
  • trunk/libs/libpthread/Makefile

    r444 r445  
    11############################################################################
    2 #                    Makefile for the ALMOS-MKH "mini-pthread"             #
     2#               Makefile for the "pthread" library.                        #
    33############################################################################
    44
    55-include ../../params-soft.mk
     6
    67ifeq ($(ARCH_NAME),)
    78$(error Please define in ARCH_NAME parameter in params-soft.mk!)
     
    910
    1011SRCS = pthread.c
    11 OBJS = $(addprefix build/, $(SRCS:.c=.o))
    12 #       $(HAL_ARCH)/build/core/hal_user.o
    1312
    14 INCLUDES = -I. -I$(HAL)/generic -I$(LIBC_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE)
     13OBJS = $(addprefix build/, $(SRCS:.c=.o)) \
     14       $(HAL_ARCH)/build/core/hal_user.o
    1515
    16 libs : build/lib/libpthread.a headers
     16INCLUDES = -I.                     \
     17           -I$(LIBC_PATH)          \
     18           -I$(LIBALMOSMKH_PATH)   \
     19           -I$(SHARED_INCLUDE)     \
     20           -I$(HAL)/generic        \
     21           -I$(HAL_ARCH)/core      \
     22           -I$(KERNEL)
     23
     24libs : build/lib/libpthread.a  headers
    1725
    1826build :
     
    2432        $(MAKE) -C $(HAL_ARCH)
    2533
    26 ../mini-libc/build/%.o:
    27         $(MAKE) -C ../libc -f Makefile.tsar
    28 
    2934build/%.o : %.c %.h
    3035        $(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
     
    3237
    3338headers: build
    34         cp $(SRCS:.c=.h) build/include/.
     39        cp $(SRCS:.c=.h)  build/include/.
    3540
    3641
    37 build/lib/libpthread.a: build $(OBJS)
    38         $(AR) rc $@ $(OBJS) #$(OBJS_LIBC)
     42build/lib/libpthread.a: build  $(OBJS)
     43        $(AR) rc $@ $(OBJS)
    3944        $(RANLIB) $@
    4045
  • trunk/libs/libpthread/pthread.c

    r444 r445  
    11/*
    2  * pthread.c - User side pthread related functions implementation.
     2 * pthread.c - User leve <pthread> library implementation.
    33 *
    44 * Author     Alain Greiner (2016,2017,2018)
     
    2323
    2424#include <hal_user.h>
     25#include <hal_types.h>
    2526#include <stdio.h>
    2627#include <stdlib.h>
    2728#include <pthread.h>
    28 #include <assert.h>
    29 #include <almos-mkh.h>
     29#include <almosmkh.h>
    3030#include <syscalls_numbers.h>
    3131
    3232#define PTHREAD_MUTEX_DEBUG     0
    3333#define PTHREAD_BARRIER_DEBUG   0
    34 
    35 #define  reg_t     int
    3634
    3735////////////////////////////////////////////////////////////////////////////////////////////
     
    205203
    206204    // check attributes
    207     assert( x_size <= QDT_XMAX );
    208     assert( y_size <= QDT_YMAX );
    209     assert( x_size * y_size * nthreads == count );
     205    if( (x_size * y_size * nthreads) != count )
     206    {
     207        printf("\[ERROR] in %s : count != x_size * y_size * nthreads/n", __FUNCTION__);
     208        exit( EXIT_FAILURE );
     209    }
    210210   
    211211    // compute SQT levels
     
    319319    else                                               // not the last thread
    320320    {
    321         // poll sense
    322321        while( 1 )
    323322        {
     323            // poll sense
    324324            if( node->sense == expected ) break;
     325
     326            // deschedule
     327            pthread_yield();
    325328        }
    326329
  • trunk/libs/libpthread/pthread.h

    r444 r445  
    11/*
    2  * pthread.h - User side pthread related library definition.
     2 * pthread.h - User level <pthread> library definition.
    33 *
    44 * Author     Alain Greiner (2016,2017)
     
    2525#define _PTHREAD_H_
    2626
    27 #include <almos-mkh/pthread.h>
    28 
     27#include <shared_pthread.h>
    2928
    3029//////////////////////////////////////////////////////////////////////////////////////////////
     
    7877int pthread_exit( void * exit_value );
    7978
    80 
    81 
    82 // TODO n'existe pas dans pthread
    8379/*********************************************************************************************
    8480 * This function calls the scheduler for the core running the calling thread.
     81 * WARNING: It is not defined by POSIX.
    8582 *********************************************************************************************
    8683 * @ return always 0.
  • trunk/libs/mini-libc/Makefile

    r444 r445  
    11############################################################################
    2 #                  Makefile for the ALMOS-MKH "mini-libc"                  #
     2#          Makefile for the "mini-libc" library.                           #
    33############################################################################
    44
    55-include ../../params-soft.mk
     6
    67ifeq ($(ARCH_NAME),)
    78$(error Please define in ARCH_NAME parameter in params-soft.mk!)
    89endif
    910
    10 SRCS = ctype.c  dirent.c  fcntl.c  signal.c  stdio.c  stdlib.c  string.c  strings.c  sys/mman.c  sys/stat.c  sys/time.c  sys/wait.c  unistd.c
     11SRCS = ctype.c   \
     12       dirent.c  \
     13       fcntl.c   \
     14       mman.c    \
     15       signal.c  \
     16       stat.c    \
     17       stdio.c   \
     18       stdlib.c  \
     19       string.c  \
     20       strings.c \
     21       time.c    \
     22       unistd.c  \
     23       wait.c 
     24
    1125OBJS = $(addprefix build/, $(SRCS:.c=.o)) \
    1226       $(HAL_ARCH)/build/core/hal_user.o
    1327
    14 INCLUDES = -I. -I$(HAL)/generic -I$(LIBPTHREAD_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE)
     28INCLUDES = -I.                     \
     29           -I$(LIBPTHREAD_PATH)    \
     30           -I$(LIBALMOSMKH_PATH)   \
     31           -I$(SHARED_INCLUDE)     \
     32           -I$(HAL)/generic        \
     33           -I$(HAL_ARCH)/core      \
     34           -I$(KERNEL)
    1535
    16 libs : build/lib/libc.a headers
     36libs : build/lib/libc.a  headers
    1737
    1838build :
    1939        @mkdir build
    20         @mkdir build/sys
    2140        @mkdir build/lib
    2241        @mkdir build/include
     
    2645        $(MAKE) -C $(HAL_ARCH)
    2746
    28 
    2947build/%.o : %.c %.h
    3048        $(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
     
    3250
    3351headers: build
    34         cp $(SRCS:.c=.h) assert.h build/include/.
    35         cp sys/*.h build/include/sys/.
     52        cp ctype.h   build/include/.
     53        cp dirent.h  build/include/.
     54        cp fcntl.h   build/include/.
     55        cp mman.h    build/include/sys/.
     56        cp signal.h  build/include/.
     57        cp stat.h    build/include/sys/.
     58        cp stdio.h   build/include/.
     59        cp stdlib.h  build/include/.
     60        cp string.h  build/include/.
     61        cp strings.h build/include/.
     62        cp time.h    build/include/.
     63        cp unistd.h  build/include/.
     64        cp wait.h    build/include/sys/.
    3665
    3766build/lib/libc.a: build $(OBJS)
    3867        $(AR) rc $@ $(OBJS)
    39         ranlib $@
    4068        $(RANLIB) $@
    4169
    4270.PHONY = build clean headers
    4371
    44 
    4572clean:
    4673        rm -rf build/
  • trunk/libs/mini-libc/stdio.c

    r444 r445  
    11/*
    2  * stdio.c - User side system calls implementation.
     2 * stdio.c - User level <stdio> library implementation.
    33 *
    4  * Author     Alain Greiner (2016,2017)
     4 * Author     Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2424#include <stdio.h>
    2525#include <stdarg.h>
     26#include <almosmkh.h>
    2627#include <unistd.h>
    27 #include <almos-mkh.h>
     28
    2829//////////////////////////////////////////
    2930static int xprintf( char         * string,
  • trunk/libs/mini-libc/stdio.h

    r444 r445  
    11/*
    2  * stdio.h - User side syscalls definition.
     2 * stdio.h - User level <stdio> library definition.
    33 *
    4  * Author     Alain Greiner (2016,2017)
     4 * Author     Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2525#define _STDIO_H_
    2626
    27 #include <almos-mkh/stdio.h>
     27/*********************************************************************************************
     28 * This file defines the user level, TXT related <stdio> library.
     29 * These functions call the read() and write() functions defined in the <unistd> library
     30 * to access the TXT terminal.
     31 ********************************************************************************************/
    2832
    29 #define  NULL  (void *)0
     33
    3034/*********************************************************************************************
    3135 * This function writes a formated string to the standard "stdout" stream.
     
    5458 * it cheks that the formated string fit in the buffer length.
    5559 *********************************************************************************************
    56  * @ string    :  pointer on target buffer.
     60 * @ string    : pointer on target buffer.
    5761 * @ length    : max bumber of characters in target buffer.
    5862 * @ format    : formated string.
  • trunk/libs/mini-libc/stdlib.c

    r444 r445  
    11/*
    2  * stdlib.c - User level C library implementation.
     2 * stdlib.c - User level <stdlib> library implementation.
    33 *
    44 * Author     Alain Greiner (2016,2017)
     
    2323
    2424#include <stdlib.h>
     25#include <hal_types.h>
     26#include <hal_user.h>
     27#include <almosmkh.h>
    2528#include <stdio.h>
    26 #include <almos-mkh.h>
    27 #include <hal_user.h>
    2829#include <syscalls_numbers.h>
    2930
    30 #define  reg_t     int
    3131//////////////////////////
    3232int atoi(const char * str)
     
    114114}
    115115
    116 
    117 
    118116//////////
    119117int rand()
     
    141139}
    142140
    143 
    144 
    145 
    146141//////////////////////////////////
    147142void * malloc( unsigned int size )
     
    154149    return remote_malloc( size, cxy );
    155150}
    156 
    157 
    158151
    159152///////////////////////////////////
  • trunk/libs/mini-libc/stdlib.h

    r444 r445  
    11/*
    2  * stdlib.h - User level library definition.
     2 * stdlib.h - User level <stdlib> library definition.
    33 *
    44 * Author     Alain Greiner (2016,2017)
     
    2525#define _STDLIB_H
    2626
    27 #include <almos-mkh/stdlib.h>
     27/*****************************************************************************************
     28 * This file defines the user side <stdlib> library.
     29 * Some functions make a system call to access the kernel VFS.
     30 * The user/kernel shared structures and mnemonics are defined in
     31 * the <syscalls/shared_include/shared_fcntl.h> file.
     32 ****************************************************************************************/
     33
     34#include <shared_stdlib.h>
    2835
    2936/*****************************************************************************************
     
    3441void exit( int status );
    3542
     43/*********************************************************************************************
     44 * This function translates an ascii character string to an integer value.
     45 *********************************************************************************************
     46 * @ str   : pointer on charactter string.
     47 * @ return an integer value.
     48 ********************************************************************************************/
     49int atoi(const char * str );
    3650
    3751/*********************************************************************************************
    38  * This function TODO
     52 * This function translates an ascii character string to a float value.
    3953 *********************************************************************************************
     54 * @ str   : pointer on charactter string.
     55 * @ return a double value.
    4056 ********************************************************************************************/
    41 int atoi(const char *str);
    42 
    43 /*********************************************************************************************
    44  * This function TODO
    45  *********************************************************************************************
    46  ********************************************************************************************/
    47 double atof(const char *str);
     57double atof(const char * str );
    4858
    4959/*********************************************************************************************
     
    7282 ****************************************************************************************/
    7383void * malloc( unsigned int size );
    74 
    7584
    7685/*****************************************************************************************
     
    109118void * calloc( unsigned int count,
    110119               unsigned int size );
     120
    111121#endif  // _STDLIB_H_
  • trunk/libs/mini-libc/string.c

    r444 r445  
    11/*
    2  * string.c - Character string handling API implementation.
     2 * string.c - User level <string> library implementation.
    33 *
    4  * Author     Alain Greiner (2016,2017)
     4 * Author     Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
  • trunk/libs/mini-libc/string.h

    r444 r445  
    11/*
    2  * string.h - Caracter string handling API definition.
     2 * string.h - User level <string> library definition.
    33 *
    4  * Author     Alain Greiner (2016,2017)
     4 * Author     Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2525#define _STRING_H_
    2626
     27/*****************************************************************************************
     28 * This file defines the user level, character string related <string> library.
     29 * These functions do not use any syscall.
     30 ****************************************************************************************/
     31
     32
    2733/********************************************************************************************
    2834 * This function returns the length of a character string.
     
    4147 *******************************************************************************************/
    4248unsigned int strnlen( const char * str,
    43                   unsigned int     maxlen );
     49                      unsigned int     maxlen );
    4450
    4551/********************************************************************************************
  • trunk/params-hard.mk

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

    r444 r445  
    11
    2 #put your absolute path to almos-mkh dir here
     2# define absolute path to almos-mkh directory
    33ALMOSMKH_DIR = /Users/alain/soc/almos-mkh
    44
     5# Select the libc
    56LIBC_NAME = mini-libc
    67#LIBC_NAME = newlib
    78
     9# Select the target architecture
    810ARCH_NAME = tsar_mips32
    911#ARCH_NAME = x86_64
    1012
    11 LIBPTHREAD_NAME = mini-libpthread
    12 
     13# check
    1314ifeq ($(ALMOSMKH_DIR),)
    1415$(error Please define ALMOSMKH_DIR parameter in params-soft.mk!)
    1516endif
    1617
     18ifeq ($(ARCH_NAME),)
     19$(error Please define ARCH_NAME parameter in params-soft.mk!)
     20endif
    1721
     22# define path for LIBC
    1823ifeq ($(LIBC_NAME), mini-libc)
    19   LIBC_PATH = $(ALMOSMKH_DIR)/libs/mini-libc/
    20   LIBC = $(LIBC_PATH)/build/lib/
     24  LIBC_PATH    = $(ALMOSMKH_DIR)/libs/mini-libc/
     25  LIBC         = $(LIBC_PATH)/build/lib/
    2126  LIBC_INCLUDE = $(LIBC_PATH)/build/include/
    2227endif
     
    2631  endif
    2732  #TODO for x86
    28   LIBC_PATH = $(ALMOSMKH_DIR)/libs/newlib/
    29   LIBC = $(LIBC_PATH)/build/$(ARCH_NEWLIB)-almosmkh/lib/
     33  LIBC_PATH    = $(ALMOSMKH_DIR)/libs/newlib/
     34  LIBC         = $(LIBC_PATH)/build/$(ARCH_NEWLIB)-almosmkh/lib/
    3035  LIBC_INCLUDE = $(LIBC_PATH)/build/$(ARCH_NEWLIB)-almosmkh/include/
    3136endif
    3237
    33 ifeq ($(LIBPTHREAD_NAME), mini-libpthread)
    34   LIBPTHREAD_PATH = $(ALMOSMKH_DIR)/libs/mini-libpthread/
    35 endif
     38# define paths for LIBPTHREAD
     39LIBPTHREAD_PATH    = $(ALMOSMKH_DIR)/libs/libpthread/
     40LIBPTHREAD         = $(LIBPTHREAD_PATH)/build/lib/
     41LIBPTHREAD_INCLUDE = $(LIBPTHREAD_PATH)/build/include/
    3642
    37 LIBALMOSMKH_PATH = $(ALMOSMKH_DIR)/libs/libalmos-mkh
    38 #Define path to .a and headers files for libc and libpthread
    39 LIBPTHREAD = $(LIBPTHREAD_PATH)/build/lib/
    40 LIBPTHREAD_INCLUDE = $(LIBPTHREAD_PATH)/build/include/
    41 LIBALMOSMKH = $(LIBALMOSMKH_PATH)/build/lib/
     43# define paths for LIBALMOSMKH
     44LIBALMOSMKH_PATH    = $(ALMOSMKH_DIR)/libs/libalmosmkh
     45LIBALMOSMKH         = $(LIBALMOSMKH_PATH)/build/lib/
    4246LIBALMOSMKH_INCLUDE = $(LIBALMOSMKH_PATH)/build/include/
    4347
     48# define paths for HAL
     49HAL      = $(ALMOSMKH_DIR)/hal
     50HAL_ARCH = $(HAL)/$(ARCH_NAME)
    4451
    45 HAL  = $(ALMOSMKH_DIR)/hal
    46 KERNEL = $(ALMOSMKH_DIR)/kernel
     52KERNEL   = $(ALMOSMKH_DIR)/kernel
     53
    4754SHARED_INCLUDE = $(KERNEL)/syscalls/shared_include/
    4855
     
    7279endif
    7380
    74 ifeq ($(ARCH_NAME),)
    75 $(error Your ARCH_NAME is not support, check params-soft.mk!)
    76 endif
    77 
    7881BOOTLOADER_PATH = boot/$(ARCH_NAME)
    79 HAL_ARCH = $(HAL)/$(ARCH_NAME)
    8082
    8183
  • trunk/user/idbg/Makefile

    r444 r445  
    1111OBJS = build/idbg.o
    1212
    13 INCLUDES = -I. -I$(LIBC_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE) -I$(LIBPTHREAD_INCLUDE)
     13INCLUDES = -I.                      \
     14           -I$(LIBC_INCLUDE)        \
     15           -I$(LIBPTHREAD_INCLUDE)  \
     16           -I$(LIBALMOSMKH_INCLUDE) \
     17           -I$(SHARED_INCLUDE)
    1418
    1519compile: dirs build/idbg.elf
    1620
    1721build/idbg.elf : $(OBJS) idbg.ld
    18         $(LD) -o $@ -T idbg.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH)  -lpthread -lc -lalmos-mkh -lc -lpthread -lc -lalmos-mkh -lpthread -lc
     22        $(LD) -o $@ -T idbg.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -lpthread -lc -lalmosmkh -lc -lpthread
    1923        $(DU) -D $@ > $@.txt
    2024
  • trunk/user/idbg/idbg.c

    r444 r445  
    88///////////////////////////////////////////////////////////////////////////////
    99
    10 
    1110#include <stdlib.h>
    1211#include <stdio.h>
    13 #include <almos-mkh.h>
     12#include <almosmkh.h>
    1413
    1514///////////
  • trunk/user/init/Makefile

    r444 r445  
    11#########################################################################
    2 # Makefile for the ALMOS-MKH "init" application
     2# Makefile for the "init" application
    33#########################################################################
    44
     
    1111OBJS = build/init.o
    1212
    13 INCLUDES = -I.                   \
    14            -I../..               \
    15            -I$(LIBC_INCLUDE)/    \
    16            -I$(LIBPTHREAD_INCLUDE) \
     13INCLUDES = -I.                      \
     14           -I../..                  \
     15           -I$(LIBC_INCLUDE)        \
     16           -I$(LIBPTHREAD_INCLUDE)  \
    1717           -I$(LIBALMOSMKH_INCLUDE) \
    1818           -I$(SHARED_INCLUDE)
    1919
    2020compile : dirs build/init.elf
     21
    2122build/init.elf : $(OBJS) init.ld
    22         $(LD) -o $@ -T init.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -lc -lpthread -lalmos-mkh -lpthread -lc
     23        $(LD) -o $@ -T init.ld $(OBJS) -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -lc -lpthread -lalmosmkh -lpthread -lc
    2324        $(DU) -D $@ > $@.txt
    2425
  • trunk/user/init/init.c

    r444 r445  
    1717#include <stdio.h>
    1818#include <pthread.h>
    19 #include <almos-mkh.h>
    20 #include <assert.h>
     19#include <almosmkh.h>
    2120#include <sys/wait.h>
    2221
    2322#define DEBUG_PROCESS_INIT    0
    2423
    25 // TODO make the cxy computation portable [AG]
     24// TODO make the cxy computation portable
     25// and avoid this TSAR specific define [AG]
     26
    2627#define CXY_FROM_XY( x , y )  ((x<<4) + y)
     28
     29// TODO improve the get_config() syscall to return nb_txt_channels
     30// and avoid the hard_config include [AG]
    2731
    2832//////////
     
    3741
    3842    // check number of TXT channels
    39     assert( NB_TXT_CHANNELS > 1 );
     43    if( NB_TXT_CHANNELS < 2 )
     44    {
     45        printf("\n[ERROR] in init process : number of TXT channels must be larger than 1\n");
     46        exit( EXIT_FAILURE );
     47    }
    4048
    4149    // create the KSH processes (one per user terminal)
     
    7381             display_string( string );
    7482        }
     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 );
    7588    }
    7689 
  • trunk/user/ksh/Makefile

    r444 r445  
    11#########################################################################
    2 # Makefile for the ALMOS-MKH "ksh" application
     2#     Makefile for the "ksh" application                                #
    33#########################################################################
    44
    55-include ../../params-soft.mk
     6
    67ifeq ($(ARCH_NAME),)
    78$(error Please define in ARCH_NAME parameter in params-soft.mk!)
     
    1011OBJS = build/ksh.o
    1112
    12 INCLUDES = -I. -I$(LIBC_INCLUDE) -I$(LIBPTHREAD_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE)
     13INCLUDES = -I.                      \
     14           -I$(LIBC_INCLUDE)        \
     15           -I$(LIBPTHREAD_INCLUDE)  \
     16           -I$(LIBALMOSMKH_INCLUDE) \
     17           -I$(SHARED_INCLUDE)
    1318
    1419compile: dirs build/ksh.elf
     20
    1521build/ksh.elf : $(OBJS) ksh.ld
    16         $(LD) -o $@ -T ksh.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -lpthread -lc -lalmos-mkh -lc -lpthread -lc
     22        $(LD) -o $@ -T ksh.ld $(OBJS) -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -lc -lpthread -lalmosmkh -lpthread -lc
    1723        $(DU) -D $@ > $@.txt
    1824
  • trunk/user/ksh/ksh.c

    r444 r445  
    1313#include <signal.h>
    1414#include <unistd.h>
    15 #include <almos-mkh.h>
     15#include <almosmkh.h>
    1616
    1717#define CMD_MAX_SIZE   (256)    // max number of characters in one command
     
    320320
    321321        display_chdev();
     322    }
     323    else if( strcmp( argv[1] , "dqdt" ) == 0 )
     324    {
     325        if( argc != 2 )
     326        {
     327                    printf("  usage: display dqdt\n");
     328                    return;
     329            }
     330
     331        display_dqdt();
    322332    }
    323333    else
  • trunk/user/pgcd/Makefile

    r444 r445  
    11############################################################################
    2 # Makefile for the ALMOS-MKH "pgcd" application
     2# Makefile for the "pgcd" application                                      #
    33############################################################################
    44
     
    1111OBJS = build/pgcd.o
    1212
    13 INCLUDES = -I. -I$(LIBC_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE) -I$(LIBPTHREAD_INCLUDE)
     13INCLUDES = -I.                      \
     14           -I$(LIBC_INCLUDE)        \
     15           -I$(LIBPTHREAD_INCLUDE)  \
     16           -I$(LIBALMOSMKH_INCLUDE) \
     17           -I$(SHARED_INCLUDE)
    1418
    1519compile: dirs build/pgcd.elf
    1620
    1721build/pgcd.elf : $(OBJS) pgcd.ld
    18         $(LD) -o $@ -T pgcd.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBALMOSMKH) -L$(LIBPTHREAD) -lalmos-mkh -lc -lalmos-mkh -lpthread -lc
     22        $(LD) -o $@ -T pgcd.ld $(OBJS) -L$(LIBC) -L$(LIBALMOSMKH) -L$(LIBPTHREAD) -lc -lpthread -lalmosmkh -lpthread -lc
    1923        $(DU) -D $@ > $@.txt
    2024
  • trunk/user/pgcd/pgcd.c

    r444 r445  
    88
    99
    10 #include <stdlib.h>
    1110#include <stdio.h>
    12 #include <almos-mkh.h>
     11#include <almosmkh.h>
    1312
    1413///////////
     
    2019
    2120    get_cycle( &cycle );
    22     printf( "\n[PGCD] starts / cycle %d\n", (unsigned int)cycle );
     21    printf( "\n\n[PGCD] starts / cycle %d\n", (unsigned int)cycle );
    2322
    2423    while (1)
  • trunk/user/sort/Makefile

    r444 r445  
    1111OBJS = build/sort.o
    1212
    13 INCLUDES = -I. -I$(LIBC_INCLUDE) -I$(LIBPTHREAD_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE)
     13INCLUDES = -I.                      \
     14           -I$(LIBC_INCLUDE)        \
     15           -I$(LIBPTHREAD_INCLUDE)  \
     16           -I$(LIBALMOSMKH_INCLUDE) \
     17           -I$(SHARED_INCLUDE)
    1418
    1519compile: dirs build/sort.elf
    1620
    1721build/sort.elf : $(OBJS) sort.ld
    18         $(LD) -o $@ -T sort.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -lpthread -lalmos-mkh -lc
     22        $(LD) -o $@ -T sort.ld $(OBJS) -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -lc -lpthread -lalmosmkh -lpthread -lc
    1923        $(DU) -D $@ > $@.txt
    2024
  • trunk/user/sort/sort.c

    r444 r445  
    2525#include <stdlib.h>
    2626#include <pthread.h>
    27 #include <almos-mkh.h>
     27#include <almosmkh.h>
    2828
    2929#define ARRAY_LENGTH        0x400    // 1024 values
     
    163163    bubbleSort( array0, items, items * thread_uid );
    164164
    165     printf("\n[SORT] thread[%d] / stage 0 completed\n", thread_uid );
     165    printf("\n[SORT] thread[%d] : stage 0 completed\n", thread_uid );
    166166
    167167    /////////////////////////////////
     
    177177        if( (thread_uid & ((1<<i)-1)) == 0 )
    178178        {
    179             printf("\n[SORT] thread[%d] / stage %d start\n", thread_uid , i );
     179            printf("\n[SORT] thread[%d] : stage %d start\n", thread_uid , i );
    180180
    181181            if((i % 2) == 1)               // odd stage
     
    197197                   items * thread_uid );
    198198
    199             printf("\n[SORT] thread[%d] / stage %d completed\n", thread_uid , i );
     199            printf("\n[SORT] thread[%d] : stage %d completed\n", thread_uid , i );
    200200        }
    201201
     
    328328
    329329#if INTERACTIVE_MODE
    330 idbg();
     330// idbg();
    331331#endif
    332332            }
     
    336336    get_cycle( &cycle );
    337337    printf("\n[SORT] main completes threads create at cycle %d\n", (unsigned int)cycle );
    338 
    339     // main run also the sort() function
    340     sort( &arg[main_uid] );
    341338
    342339#if INTERACTIVE_MODE
     
    344341#endif
    345342   
     343    // the main thread run also the sort() function
     344    sort( &arg[main_uid] );
     345
    346346    // Check result
    347347    int    success = 1;
Note: See TracChangeset for help on using the changeset viewer.