Changeset 444 for trunk


Ignore:
Timestamp:
May 16, 2018, 8:31:35 PM (6 years ago)
Author:
satin@…
Message:

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

Location:
trunk
Files:
7047 added
2 deleted
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r443 r444  
    9090        $(MAKE) -C $(LIBC_PATH) clean
    9191        $(MAKE) -C $(LIBPTHREAD_PATH) clean
     92        $(MAKE) -C $(LIBALMOSMKH_PATH) clean
    9293        $(MAKE) -C user/init clean
    9394        $(MAKE) -C user/ksh clean
     
    133134# Rules to generate the user level libraries
    134135build_libs: build_hal
     136        $(MAKE) -C $(LIBALMOSMKH_PATH) headers
     137        $(MAKE) -C $(LIBPTHREAD_PATH) headers
    135138        $(MAKE) -C $(LIBC_PATH)
     139        $(MAKE) -C $(LIBALMOSMKH_PATH)
    136140        $(MAKE) -C $(LIBPTHREAD_PATH)
    137141
  • trunk/hal/tsar_mips32/Makefile

    r440 r444  
    4242               $(HAL_ARCH)/build/core/hal_user.o
    4343
    44 HAL_INCLUDE =    -I$(KERNEL)             \
    45                  -I$(HAL_ARCH)/drivers   \
    46                  -I$(HAL)/generic        \
    47                  -I$(HAL_ARCH)/core      \
    48                  -I../../tools/arch_info \
    49                  -I$(KERNEL)/kern        \
    50                  -I$(KERNEL)/mm          \
    51                  -I$(KERNEL)/fs          \
    52                  -I$(KERNEL)/syscalls    \
    53                  -I$(KERNEL)/devices     \
     44HAL_INCLUDE =     -I$(KERNEL) \
     45                 -I$(HAL_ARCH)/drivers \
     46                 -I$(HAL)/generic             \
     47                 -I$(HAL_ARCH)/core    \
     48                 -I../../tools/arch_info         \
     49                 -I$(KERNEL)/kern \
     50                 -I$(KERNEL)/mm   \
     51                 -I$(KERNEL)/fs   \
     52                 -I$(KERNEL)/syscalls   \
     53                 -I$(SHARED_INCLUDE)  \
     54                 -I$(KERNEL)/devices    \
    5455                 -I$(KERNEL)/libk
    5556
  • trunk/hal/x86_64/Makefile

    r439 r444  
    5353                 -I$(KERNEL)/fs   \
    5454                 -I$(KERNEL)/syscalls   \
     55                 -I$(SHARED_INCLUDE)  \
    5556                 -I$(KERNEL)/devices    \
    5657                 -I$(KERNEL)/libk
  • trunk/kernel/Makefile

    r440 r444  
    186186# List of directories to be searched for included files
    187187# when compiling for kernel.elf generation
    188 KERNEL_INCLUDE = -I.                   \
    189                  -Ikern                \
    190                  -Idevices             \
    191                  -Isyscalls            \
     188KERNEL_INCLUDE = -I.                  \
     189                 -Ikern             \
     190                 -Idevices          \
     191                 -Isyscalls         \
     192                 -I$(SHARED_INCLUDE)  \
    192193                 -I$(HAL_ARCH)/drivers \
    193194                 -Isyscalls            \
  • trunk/kernel/syscalls/shared_syscalls.h

    r437 r444  
    1 /*
    2  * syscalls.h - Shared Kernel/User informations for syscalls.
    3  *
    4  * Author     Alain Greiner (2016,2017)
    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 
    241#ifndef _SHARED_SYSCALLS_H_
    252#define _SHARED_SYSCALLS_H_
    263
    27 /******************************************************************************************
    28  * This enum defines the mnemonics for the syscall indexes.
    29  * It must be kept consistent with the array defined in do_syscalls.c
    30  *****************************************************************************************/
    314
    32 enum
    33 {
    34         SYS_THREAD_EXIT    = 0,
    35         SYS_THREAD_YIELD   = 1,
    36         SYS_THREAD_CREATE  = 2,
    37         SYS_THREAD_JOIN    = 3,
    38         SYS_THREAD_DETACH  = 4,
    39         SYS_THREAD_CANCEL  = 5,
    40         SYS_SEM            = 6,
    41         SYS_CONDVAR        = 7,
    42         SYS_BARRIER        = 8,
    43         SYS_MUTEX          = 9,
    44 
    45     SYS_EXIT           = 10,
    46     SYS_MUNMAP         = 11,
    47         SYS_OPEN           = 12,
    48         SYS_MMAP           = 13,
    49         SYS_READ           = 14,
    50         SYS_WRITE          = 15,
    51         SYS_LSEEK          = 16,
    52         SYS_CLOSE          = 17,
    53         SYS_UNLINK         = 18,   
    54         SYS_PIPE           = 19,
    55 
    56         SYS_CHDIR          = 20,
    57         SYS_MKDIR          = 21,
    58         SYS_MKFIFO         = 22,   
    59         SYS_OPENDIR        = 23,
    60         SYS_READDIR        = 24,
    61         SYS_CLOSEDIR       = 25,
    62         SYS_GETCWD         = 26,
    63         SYS_ISATTY         = 27,
    64         SYS_ALARM          = 28,   
    65         SYS_RMDIR          = 29,
    66 
    67         SYS_UTLS           = 30, 
    68         SYS_CHMOD          = 31,
    69         SYS_SIGNAL         = 32,
    70         SYS_TIMEOFDAY      = 33,
    71         SYS_KILL           = 34,
    72         SYS_GETPID         = 35,
    73         SYS_FORK           = 36,
    74         SYS_EXEC           = 37,
    75         SYS_STAT           = 38,     
    76         SYS_WAIT           = 39,
    77 
    78     SYS_GET_CONFIG     = 40,
    79     SYS_GET_CORE       = 41,
    80     SYS_GET_CYCLE      = 42,
    81     SYS_DISPLAY        = 43,
    82     SYS_UNDEFINED_44   = 44,   ///
    83         SYS_THREAD_SLEEP   = 45,
    84         SYS_THREAD_WAKEUP  = 46,
    85     SYS_TRACE          = 47,
    86     SYS_FG             = 48,
    87     SYS_UNDEFINED_49   = 49,   ///
    88 
    89         SYSCALLS_NR        = 50,
    90 };
    91 
    92 /*******************************************************************************************
    93  * This defines the signal type mnemonics for the kill() syscall.
    94  * WARNING : Only the three SIGKILL / SIGSTOP / SIGCONT are supported (december 2017)
    95  ******************************************************************************************/
    96 
    97 #define SIGHUP     1       /*! hangup                                                     */
    98 #define SIGINT     2       /*! interrupt                                                  */
    99 #define SIGQUIT    3       /*! quit                                                       */
    100 #define SIGILL     4       /*! illegal instruction (not reset when caught)                */
    101 #define SIGTRAP    5       /*! trace trap (not reset when caught)                         */
    102 #define SIGABRT    6       /*! used by abort, replace SIGIOT in the future                */
    103 #define SIGEMT     7       /*! EMT instruction                                            */
    104 #define SIGFPE     8       /*! floating point exception                                   */
    105 #define SIGKILL    9       /*! kill (cannot be caught or ignored)                         */
    106 #define SIGBUS     10      /*! bus error                                                  */
    107 #define SIGSEGV    11      /*! segmentation violation                                     */
    108 #define SIGSYS     12      /*! bad argument to system call                                */
    109 #define SIGPIPE    13      /*! write on a pipe with no one to read it                     */
    110 #define SIGALRM    14      /*! alarm clock                                                */
    111 #define SIGTERM    15      /*! software termination signal from kill                      */
    112 #define SIGURG     16      /*! urgent condition on IO channel                             */
    113 #define SIGSTOP    17      /*! sendable stop signal not from tty                          */
    114 #define SIGTSTP    18      /*! stop signal from tty                                       */
    115 #define SIGCONT    19      /*! continue a stopped process                                 */
    116 #define SIGCHLD    20      /*! to parent on child stop or exit                            */
    117 #define SIGTTIN    21      /*! to readers pgrp upon background tty read                   */
    118 #define SIGTTOU    22      /*! like TTIN for output if (tp->t_local&LTOSTOP)              */
    119 #define SIGIO      23      /*! input/output possible signal                               */
    120 #define SIGXCPU    24      /*! exceeded CPU time limit                                    */
    121 #define SIGXFSZ    25      /*! exceeded file size limit                                   */
    122 #define SIGVTALRM  26      /*! virtual time alarm                                         */
    123 #define SIGPROF    27      /*! profiling time alarm                                       */
    124 #define SIGWINCH   28      /*! window changed                                             */
    125 #define SIGLOST    29      /*! resource lost (eg, record-lock lost)                       */
    126 #define SIGUSR1    30      /*! user defined signal 1                                      */
    127 #define SIGUSR2    31      /*! user defined signal 2                                      */
    128 
    129 /*******************************************************************************************
    130  * This enum defines the supported terminaison status values for the exit() syscall.
    131  ******************************************************************************************/
    132 
    133 typedef enum
    134 {
    135         EXIT_SUCCESS,
    136         EXIT_FAILURE,
    137 }
    138 exit_statut_t;
    139 
    140 /*******************************************************************************************
    141  * These typedef define the POSIX thread related types.
    142  ******************************************************************************************/
    143 
    144 typedef unsigned int      sem_t;
    145 typedef unsigned int      pthread_cond_t;
    146 typedef unsigned int      pthread_condattr_t;
    147 typedef unsigned int      pthread_rwlock_t;
    148 typedef unsigned int      pthread_rwlockattr_t;
    149 typedef unsigned int      pthread_key_t;
    150 
    151 /*******************************************************************************************
    152  * This structure and enum define the attributes for the "pthread_create" syscall.
    153  ******************************************************************************************/
    154 
    155 typedef unsigned int  pthread_t;               
    156 
    157 typedef struct pthread_attr_s
    158 {
    159         unsigned int      attributes;      /*! user defined attributes bit vector             */
    160         unsigned int      cxy;             /*! target cluster identifier                      */
    161         unsigned int      lid;             /*! target core local index                        */
    162 }
    163 pthread_attr_t;
    164 
    165 enum
    166 {
    167     PT_ATTR_DETACH          = 0x0001,  /*! user defined not joinable                      */
    168     PT_ATTR_CLUSTER_DEFINED = 0x0002,  /*! user defined target cluster                    */
    169     PT_ATTR_CORE_DEFINED    = 0x0004,  /*! user defined core index in cluster             */
    170 };
    171 
    172 /*******************************************************************************************
    173  * This enum defines the operation mnemonics for operations on POSIX unnamed semaphores.
    174  ******************************************************************************************/
    175 
    176 typedef enum
    177 {
    178         SEM_INIT,
    179         SEM_DESTROY,
    180         SEM_GETVALUE,
    181         SEM_WAIT,
    182         SEM_POST,
    183 }
    184 sem_operation_t;
    185 
    186 /*******************************************************************************************
    187  * This enum defines the operation mnemonics for operations on POSIX condition variables.
    188  ******************************************************************************************/
    189 
    190 typedef enum
    191 {
    192         CONDVAR_INIT,
    193         CONDVAR_DESTROY,
    194     CONDVAR_WAIT,
    195     CONDVAR_SIGNAL,
    196     CONDVAR_BROADCAST,
    197 }
    198 condvar_operation_t;
    199 
    200 /*******************************************************************************************
    201  * This enum defines the operation mnemonics for operations on POSIX barriers.
    202  ******************************************************************************************/
    203 
    204 typedef enum
    205 {
    206         BARRIER_INIT,
    207         BARRIER_DESTROY,
    208         BARRIER_WAIT,
    209 }
    210 barrier_operation_t;
    211 
    212 /*******************************************************************************************
    213  * This enum defines the operation mnemonics for operations on POSIX mutex.
    214  ******************************************************************************************/
    215 
    216 typedef enum
    217 {
    218         MUTEX_INIT,
    219         MUTEX_DESTROY,
    220         MUTEX_LOCK,
    221         MUTEX_UNLOCK,
    222 }
    223 mutex_operation_t;
    224 
    225 /*******************************************************************************************
    226  * This enum defines the attributes bit-vector for an "open" syscall.
    227  ******************************************************************************************/
    228 
    229 typedef enum
    230 {
    231     O_RDONLY   = 0x0010000,    /*! open file in read-only mode                            */
    232     O_WRONLY   = 0x0020000,    /*! open file in write-only mode                           */
    233     O_RDWR     = 0x0030000,    /*! open file in read/write mode                           */
    234     O_NONBLOCK = 0x0040000,    /*! do not block if data non available                     */
    235     O_APPEND   = 0x0080000,    /*! append on each write                                   */
    236     O_CREAT    = 0x0100000,    /*! create file if it does not exist                       */
    237     O_TRUNC    = 0x0200000,    /*! file length is forced to 0                             */
    238     O_EXCL     = 0x0400000,    /*! error if VFS_O_CREAT and file exist                    */
    239     O_SYNC         = 0x0800000,    /*! synchronize File System on each write                  */
    240     O_CLOEXEC  = 0x1000000,    /*! set the close-on-exec flag in file descriptor          */
    241     O_DIR      = 0x2000000,    /*! new file descriptor is for a directory                 */
    242 }
    243 open_attr_t;
    244 
    245 /*******************************************************************************************
    246  * This structure contains the arguments passed to the "mmap" syscall.
    247  ******************************************************************************************/
    248 
    249 #define      MAP_FAILED  0
    250 
    251 typedef enum
    252 {
    253     PROT_NONE   = 0x0,         /*! no access                                              */
    254     PROT_EXEC   = 0x1,         /*! executable                                             */
    255     PROT_WRITE  = 0x2,         /*! writable                                               */
    256     PROT_READ   = 0x4,         /*! readable                                               */
    257 }
    258 mmap_prot_t;
    259 
    260 typedef enum
    261 {
    262     MAP_FILE    = 0x00000000,  /*! map an open file defined by its fdid                   */
    263     MAP_ANON    = 0x00000001,  /*! map an anonymous vseg in local cluster                 */
    264     MAP_REMOTE  = 0x00000002,  /*! map an anonymous vseg in remote cluster (cxy == fdid)  */
    265     MAP_PRIVATE = 0x00000010,  /*!                                                        */
    266     MAP_SHARED  = 0x00000020,  /*!                                                        */
    267     MAP_FIXED   = 0x00000100,  /*! non supported                                          */
    268 }
    269 mmap_flags_t;
    270 
    271 typedef struct mmap_attr_s
    272 {
    273         void         * addr;       /*! requested virtual address (unused : should be NULL)    */
    274         unsigned int   length;     /*! requested vseg size (bytes)                            */
    275         unsigned int   prot;       /*! access modes                                           */
    276         unsigned int   flags;      /*! MAP_FILE / MAP_ANON / MAP_PRIVATE / MAP_SHARED         */
    277         unsigned int   fdid;       /*! file descriptor index (if MAP_FILE)                    */
    278         unsigned int   offset;     /*! file offset (if MAP_FILE)                              */
    279 }
    280 mmap_attr_t;
    281 
    282 /*******************************************************************************************
    283  * This enum defines the operation mnemonics for the "lseek" syscall.
    284  ******************************************************************************************/
    285 
    286 typedef enum
    287 {
    288     SEEK_SET  = 0,             /*! new_offset <= offset                                   */
    289     SEEK_CUR  = 1,             /*! new_offset <= current_offset + offset                  */
    290     SEEK_END  = 2,             /*! new_offset <= current_size + offset                    */
    291 }
    292 lseek_operation_t;
    293 
    294 /*******************************************************************************************
    295  * This enum defines the operation mnemonics for the "utls" syscall (Thread Local Storage).
    296  ******************************************************************************************/
    297 
    298 typedef enum
    299 {
    300     UTLS_SET       = 1,
    301     UTLS_GET       = 2,
    302     UTLS_GET_ERRNO = 3,
    303 }
    304 utls_operation_t;
    305 
    306 /*******************************************************************************************
    307  * This enum defines the operation mnemonics for the "trace" syscall.
    308  ******************************************************************************************/
    309 
    310 typedef enum
    311 {
    312     TRACE_ON       = 0,
    313     TRACE_OFF      = 1,
    314 }
    315 trace_operation_t;
    316 
    317 /*******************************************************************************************
    318  * This enum defines the type of structure for the "display" syscall.
    319  ******************************************************************************************/
    320 
    321 typedef enum
    322 {
    323     DISPLAY_STRING            = 0,
    324     DISPLAY_VMM               = 1,
    325     DISPLAY_SCHED             = 2,
    326     DISPLAY_CLUSTER_PROCESSES = 3,
    327     DISPLAY_VFS               = 4,
    328     DISPLAY_CHDEV             = 5,
    329     DISPLAY_TXT_PROCESSES     = 6,
    330 }
    331 display_type_t;
    332 
    333 /******************************************************************************************
    334  * This structure define the informations associated to a file descriptor,
    335  * returned to user space by the stat() system call.
    336  *****************************************************************************************/
    337 
    338 typedef struct stat
    339 {
    340         unsigned int    dev;        /*! ID of device containing file                             */
    341         unsigned int    inum;       /*! inode number                                             */
    342         unsigned int    mode;       /*! protection                                               */
    343         unsigned int    nlink;      /*! number of hard links                                     */
    344         unsigned int    uid;        /*! user ID of owner                                         */
    345         unsigned int    gid;        /*! group ID of owner                                        */
    346         unsigned int    rdev;       /*! device ID (if special file)                              */
    347         unsigned int    size;       /*! total size, in bytes                                     */
    348         unsigned int    blksize;    /*! blocksize for file system I/O                            */
    349         unsigned int    blocks;     /*! number of 512B blocks allocated                          */
    350 }
    351 stat_t;
    352 
    353 /*******************************************************************************************
    354  * These two structure defines the informations returned to user by the opendir()
    355  * function, used by the readdir() function, and released by the closedir() function.
    356  * - "DIR" describes the complete directory.
    357  * - "dirent" describes one directory entry.
    358  ******************************************************************************************/
    359 
    360 #define DIRENT_NAME_MAX_LENGTH  56
    361 #define DIRENT_MAX_NUMBER       63
    362 
    363 struct dirent
    364 {
    365     unsigned int   inum;                                /*! inode identifier              */
    366     unsigned int   type;                                /*! inode type                    */
    367     char           name[DIRENT_NAME_MAX_LENGTH];        /*! directory entry name          */
    368 };
    369 
    370 typedef struct user_directory
    371 {
    372     struct dirent   entry[DIRENT_MAX_NUMBER];
    373     unsigned int    current;
    374 }
    375 DIR;
    376 
    377 /*******************************************************************************************
    378  * These two structure are used by the gettimeofday() function.
    379  ******************************************************************************************/
    380 
    381 struct timeval
    382 {
    383     unsigned int tv_sec;                    /*! seconds since Jan. 1, 1970                */
    384     unsigned int tv_usec;                   /*! and microseconds                          */
    385 };
    386 
    387 struct timezone
    388 {
    389     int          tz_minuteswest;            /*! of Greenwich                              */
    390     int          tz_dsttime;                /*! type of dst correction to apply           */
    391 };
     5#include <syscalls_numbers.h>
    3926
    3937
    394 /*********************************************************************************************
    395  * These macros can be used by the parent process to analyze a child process
    396  * termination status, as returned by the wait() syscall.
    397  * The termination state is a 32 bits word:
    398  * - the 8 LSB bits contain the user defined exit status
    399  * - the 24 other bits contain the flags defined below
    400  ********************************************************************************************/
    401 
    402 #define PROCESS_TERM_STOP  0x100            /*! process received a SIGSTOP signal           */
    403 #define PROCESS_TERM_KILL  0x200            /*! process killed by a SIGKILL signal          */
    404 #define PROCESS_TERM_EXIT  0x400            /*! process terminated by a sys_exit()          */
    405 #define PROCESS_TERM_WAIT  0x800            /*! parent process executed a sys_wait()        */
    406 
    407 #define WIFEXITED( status )       (status & PROCESS_TERM_EXIT)
    408 #define WIFSIGNALED( status )     (status & PROCESS_TERM_KILL)
    409 #define WIFSTOPPED( status )      (status & PROCESS_TERM_STOP)
    410 #define WEXITSTATUS( status )     (status & 0xFF)
     8#include <almos-mkh/almos-mkh.h>
     9#include <almos-mkh/dirent.h>
     10#include <almos-mkh/fcntl.h>
     11#include <almos-mkh/mman.h>
     12#include <almos-mkh/pthread.h>
     13#include <almos-mkh/signal.h>
     14#include <almos-mkh/stat.h>
     15#include <almos-mkh/stdio.h>
     16#include <almos-mkh/stdlib.h>
     17#include <almos-mkh/time.h>
     18#include <almos-mkh/wait.h>
    41119
    41220
    413 #endif  // _SHARED_SYSCALLS_H_
     21#endif
     22
  • trunk/libs/mini-libc/Makefile

    r440 r444  
    88endif
    99
    10 SRCS = malloc.c  stdio.c  stdlib.c  string.c
    11 
     10SRCS = 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
    1211OBJS = $(addprefix build/, $(SRCS:.c=.o)) \
    1312       $(HAL_ARCH)/build/core/hal_user.o
    1413
    15 INCLUDES = -I. -I$(KERNEL)/syscalls -I$(HAL)/generic -I../mini-libpthread
     14INCLUDES = -I. -I$(HAL)/generic -I$(LIBPTHREAD_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE)
    1615
    17 libs : build/lib/libc.a
     16libs : build/lib/libc.a headers
    1817
    1918build :
    2019        @mkdir build
     20        @mkdir build/sys
    2121        @mkdir build/lib
    2222        @mkdir build/include
     23        @mkdir build/include/sys
    2324
    2425$(HAL_ARCH)/build/core/hal_user.o :
     
    3031        $(DU) -D $@ > $@.txt
    3132
     33headers: build
     34        cp $(SRCS:.c=.h) assert.h build/include/.
     35        cp sys/*.h build/include/sys/.
     36
    3237build/lib/libc.a: build $(OBJS)
    3338        $(AR) rc $@ $(OBJS)
     39        ranlib $@
    3440        $(RANLIB) $@
    35         cp $(SRCS:.c=.h) $(HAL)/generic/hal_user.h $(KERNEL)/syscalls/shared_syscalls.h build/include/.
    3641
    37 .PHONY = build clean
     42.PHONY = build clean headers
    3843
    3944
    4045clean:
    41         rm -f build/*.o build/*.txt build/include/* build/lib/*
     46        rm -rf build/
  • trunk/libs/mini-libc/stdio.c

    r443 r444  
    2222 */
    2323
    24 #include <shared_syscalls.h>
    25 #include <hal_user.h>
    2624#include <stdio.h>
    27 #include <stdlib.h>
    28 
    29 #define  reg_t     int
    30 
    31 ///////////// POSIX standard system calls ////////////////////////////////////
    32 
    33 ///////////////////////
    34 void exit( int status )
    35 {
    36     hal_user_syscall( SYS_EXIT,
    37                       (reg_t)status, 0, 0, 0 );
     25#include <stdarg.h>
     26#include <unistd.h>
     27#include <almos-mkh.h>
     28//////////////////////////////////////////
     29static int xprintf( char         * string,
     30                    unsigned int   length,
     31                    const char   * format,
     32                    va_list      * args )
     33{
     34    unsigned int ps = 0;    // write index to the string buffer
     35
     36#define TO_STREAM(x) do { string[ps] = (x); ps++; if(ps==length) return -1; } while(0);
     37
     38xprintf_text:
     39
     40    while ( *format != 0 )
     41    {
     42
     43        if (*format == '%')   // copy argument to string
     44        {
     45            format++;
     46            goto xprintf_arguments;
     47        }
     48        else                  // copy one char to string
     49        {
     50            TO_STREAM( *format );
     51            format++;
     52        }
     53    }
     54
     55    return ps;
     56
     57xprintf_arguments:
     58
     59    {
     60        char              buf[30];    // buffer to display one number
     61        char *            pbuf;       // pointer on first char to display
     62        unsigned int      len = 0;    // number of char to display
     63        static const char HexaTab[] = "0123456789ABCDEF";
     64        unsigned int      i;
     65       
     66        // Ignore fields width and precision
     67        for ( ; (*format >= '0' && *format <= '9') || (*format == '.') ; format++ );
     68
     69        switch (*format)
     70        {
     71            case ('c'):             // char conversion
     72            {
     73                int val = va_arg( *args, int );
     74                buf[0] = val;
     75                pbuf   = buf;
     76                len    = 1;
     77                break;
     78            }
     79            case ('d'):             // decimal signed integer
     80            {
     81                int val = va_arg( *args, int );
     82                if (val < 0)
     83                {
     84                    TO_STREAM( '-' );
     85                    val = -val;
     86                }
     87                for(i = 0; i < 10; i++)
     88                {
     89
     90                    buf[9 - i] = HexaTab[val % 10];
     91                    if (!(val /= 10)) break;
     92                }
     93                len =  i + 1;
     94                pbuf = &buf[9 - i];
     95                break;
     96            }
     97            case ('u'):             // decimal unsigned integer
     98            {
     99                unsigned int val = va_arg( *args, unsigned int );
     100                for(i = 0; i < 10; i++)
     101                {
     102                    buf[9 - i] = HexaTab[val % 10];
     103                    if (!(val /= 10)) break;
     104                }
     105                len =  i + 1;
     106                pbuf = &buf[9 - i];
     107                break;
     108            }
     109            case ('x'):             // 32 bits hexadecimal
     110            case ('l'):             // 64 bits hexadecimal
     111            {
     112                unsigned int       imax;
     113                unsigned long long val;
     114               
     115                if ( *format == 'l' )   // 64 bits
     116                {
     117                    val = va_arg( *args, unsigned long long);
     118                    imax = 16;
     119                }
     120                else                    // 32 bits
     121                {
     122                    val = va_arg( *args, unsigned int);
     123                    imax = 8;
     124                }
     125               
     126                TO_STREAM( '0' );
     127                TO_STREAM( 'x' );
     128               
     129                for(i = 0; i < imax; i++)
     130                {
     131                    buf[(imax-1) - i] = HexaTab[val % 16];
     132                    if (!(val /= 16))  break;
     133                }
     134                len =  i + 1;
     135                pbuf = &buf[(imax-1) - i];
     136                break;
     137            }
     138            case ('s'):             /* string */
     139            {
     140                char* str = va_arg( *args, char* );
     141                while (str[len]) { len++; }
     142                pbuf = str;
     143                break;
     144            }
     145/*
     146            case ('f'):             // IEEE754 64 bits
     147                                    // integer part : up to 10 decimal digits
     148                                    // decimal part : 9 decimal digits
     149            {
     150                union
     151                {
     152                    double d;
     153                    unsigned long long ull;
     154                } val;
     155               
     156                val.d = va_arg( *args, double );
     157               
     158                unsigned long long mantisse;
     159                mantisse = val.ull & 0xFFFFFFFFFFFFFULL;    // mantisse
     160               
     161                unsigned int exp;
     162                exp = (unsigned int)((val.ull & 0x7FF0000000000000ULL) >> 52); // exp
     163
     164                if (exp == 0x7FF) // special values
     165                {
     166                    if (mantisse & 0xFFFFFFFFFFFFFULL)  // Not a Number
     167                    {
     168                        buf[0] = 'N';
     169                        buf[1] = 'a';
     170                        buf[2] = 'N';
     171                        len = 3;
     172                        pbuf = buf;
     173                    }
     174                    else                              // infinite
     175                    {
     176                        // inf
     177                        buf[0] = (val.ull & 0x8000000000000000ULL) ? '-' : '+';
     178                        buf[1] = 'i';
     179                        buf[2] = 'n';
     180                        buf[3] = 'f';
     181                        len = 4;
     182                        pbuf = buf;
     183                    }
     184                    break;
     185                }
     186
     187                // display sign & analyse overflow
     188                unsigned int overflow = 0;
     189                if (val.ull & 0x8000000000000000ULL)  // negative
     190                {
     191                    TO_STREAM( '-' );
     192                    val.d = val.d * -1;
     193                    if( val.d < -9999999999.0) overflow = 1;
     194                }
     195                else                                  // positive
     196                {
     197                    TO_STREAM( '+' );
     198                    if( val.d > 9999999999.0) overflow = 1;
     199                }
     200               
     201                // check overflow caused by the 10.9 format
     202                if ( overflow )   
     203                {
     204                    buf[0] = 'o';
     205                    buf[1] = 'v';
     206                    buf[2] = 'r';
     207                    len = 3;
     208                    pbuf = buf;
     209                    break;
     210                }
     211
     212                // compute integer & decimal parts
     213                unsigned int intp;                  // integer part
     214                unsigned int decp;                  // decimal part
     215                intp = (unsigned int)val.d;     
     216                val.d -= (double)intp;
     217                decp = (unsigned int)(val.d * 1000000000);
     218               
     219                // display decimal value in 10.9 format
     220                for(i = 0; i < 10; i++)
     221                {
     222                    buf[9 - i] = HexaTab[intp % 10];
     223                    if (!(intp /= 10)) break;
     224                }
     225                pbuf = &buf[9 - i];
     226                len = i+11;
     227                buf[10] = '.';
     228                for(i = 0; i < 9; i++)
     229                {
     230                    buf[19 - i] = HexaTab[decp % 10];
     231                    decp /= 10;
     232                }
     233                break;
     234            }
     235*/                   
     236            default:       // unsupported argument type
     237            {
     238                return -1;
     239            }
     240        }  // end switch on  argument type
     241
     242        format++;
     243
     244        // copy argument to string
     245        for( i = 0 ; i < len ; i++ )
     246        {
     247            TO_STREAM( pbuf[i] );
     248        }
     249       
     250        goto xprintf_text;
     251    }
     252} // end xprintf()
     253
     254//////////////////////////////////////
     255int printf( const char * format, ... )
     256{
     257    char      string[4096];
     258    va_list   args;
     259    int       count;
     260   
     261    va_start( args, format );
     262    count = xprintf( string , 4095 , format , &args );
     263    va_end( args );
     264
     265    if ( count == -1 )
     266    {
     267        display_string( "stdlib : xprintf failure" );
     268        return -1;
     269    }
     270    else
     271    {
     272        string[count] = 0;
     273        return write( 1 , &string , count + 1 );
     274    }
    38275}
    39276
    40 /////////////////////////////////
    41 int munmap( void         * addr,
    42             unsigned int   size )
    43 {
    44     return hal_user_syscall( SYS_MUNMAP,
    45                              (reg_t)addr,
    46                              (reg_t)size, 0, 0 );
     277/////////////
     278int getchar()
     279{
     280    char byte;
     281
     282    if ( read( 0 , &byte , 1 ) != 1 ) return 0;
     283    else                              return (int)byte;
    47284}
    48285
    49 ////////////////////////////////
    50 int open( const char * pathname,
    51           int          flags,
    52           int          mode )
    53 {
    54     return hal_user_syscall( SYS_OPEN,
    55                              (reg_t)pathname,
    56                              (reg_t)flags,
    57                              (reg_t)mode, 0 );
     286////////////////////
     287int putchar( int c )
     288{
     289    char byte = (char)c;
     290
     291    if( write( 1 , &byte , 1 ) != 1 ) return 0;
     292    else                              return c;
    58293}
    59294
    60 ///////////////////////////////
    61 void * mmap( void       * addr,
    62              unsigned int length,
    63              int          prot,
    64              int          flags,
    65              int          fd,
    66              unsigned int offset )
    67 {
    68     mmap_attr_t attr;
    69     attr.addr   = addr;
    70     attr.length = length;
    71     attr.prot   = prot;
    72     attr.flags  = flags;
    73     attr.fdid   = fd;
    74     attr.offset = offset;
    75 
    76     if( hal_user_syscall( SYS_MMAP,
    77                           (reg_t)&attr, 0, 0, 0 ) ) return NULL;
    78     else                                            return attr.addr;
     295///////////////////////////////////////
     296int snprintf( char           * string,
     297              unsigned int     length,
     298              const char     * format, ... )
     299{
     300    va_list   args;
     301    int       count;
     302
     303    va_start( args, format );
     304    count = xprintf( string , length , format , &args );
     305    va_end( args );
     306
     307    if( count < length ) string[count] = 0;
     308
     309    return count;
    79310}
    80311
    81 //////////////////////////
    82 int read( int          fd,
    83           void       * buf,
    84           unsigned int count )
    85 {
    86     return hal_user_syscall( SYS_READ,
    87                              (reg_t)fd,
    88                              (reg_t)buf,
    89                              (reg_t)count, 0 );
    90 }
    91 
    92 ///////////////////////////
    93 int write( int          fd,
    94            const void * buf,
    95            unsigned int count )
    96 {
    97     return hal_user_syscall( SYS_WRITE,
    98                              (reg_t)fd,
    99                              (reg_t)buf,
    100                              (reg_t)count, 0 );
    101 }
    102 
    103 ///////////////////////////
    104 int lseek( int          fd,
    105            unsigned int offset,
    106            int          whence )
    107 {
    108     return hal_user_syscall( SYS_LSEEK,
    109                              (reg_t)fd,
    110                              (reg_t)offset,
    111                              (reg_t)whence, 0 );
    112 }
    113 
    114 ///////////////////
    115 int close( int fd )
    116 {
    117     return hal_user_syscall( SYS_CLOSE,
    118                              (reg_t)fd, 0, 0, 0 );
    119 }
    120 
    121 ///////////////////////////////////
    122 int unlink( const char * pathname )
    123 {
    124     return hal_user_syscall( SYS_UNLINK,
    125                              (reg_t)pathname, 0, 0, 0 );
    126 }
    127 
    128 /////////////////////
    129 int pipe( int fd[2] )
    130 {
    131     return -1;
    132 }
    133 
    134 //////////////////////////////////
    135 int chdir( const char * pathname )
    136 {
    137     return hal_user_syscall( SYS_CHDIR,
    138                              (reg_t)pathname, 0, 0, 0 );
    139 }
    140 
    141 /////////////////////////////////
    142 int mkdir( const char * pathname,
    143            int          mode )
    144 {
    145     return hal_user_syscall( SYS_MKDIR,
    146                              (reg_t)pathname,
    147                              (reg_t)mode, 0, 0 );
    148 }
    149 
    150 //////////////////////////////////
    151 int mkfifo( const char * pathname,
    152             int          mode )
    153 {
    154     return hal_user_syscall( SYS_MKFIFO,
    155                              (reg_t)pathname,
    156                              (reg_t)mode, 0, 0 );
    157 }
    158 
    159 //////////////////////////////////////
    160 DIR * opendir( const char * pathname )
    161 {
    162     DIR   * dirp;
    163     int     error;
    164     error = hal_user_syscall( SYS_OPENDIR,
    165                               (reg_t)pathname,
    166                               (reg_t)&dirp, 0, 0 );
    167     if( error ) return NULL;
    168     else        return dirp;
    169 }
    170 
    171 /////////////////////////////////////
    172 struct dirent * readdir( DIR * dirp )
    173 {
    174     struct dirent * dentp;
    175     int             error;
    176     error = hal_user_syscall( SYS_READDIR,
    177                               (reg_t)dirp,
    178                               (reg_t)&dentp, 0, 0 );
    179     if( error ) return NULL;
    180     else        return dentp;
    181 }
    182 
    183 //////////////////////////
    184 int closedir( DIR * dirp )
    185 {
    186     return hal_user_syscall( SYS_CLOSEDIR,
    187                              (reg_t)dirp, 0, 0, 0 );
    188 }
    189 
    190 /////////////////////////////
    191 int getcwd( char       * buf,
    192             unsigned int bytes )
    193 {
    194     return hal_user_syscall( SYS_GETCWD,
    195                              (reg_t)buf,
    196                              (reg_t)bytes, 0, 0 );
    197 }
    198 
    199 ////////////////////////////
    200 int rmdir( char * pathname )
    201 {
    202     return hal_user_syscall( SYS_RMDIR,
    203                              (reg_t)pathname, 0, 0, 0 );
    204 }
    205 
    206 /////////////////////////////////
    207 int utls( unsigned int operation,
    208           unsigned int value )
    209 {
    210     return hal_user_syscall( SYS_UTLS,
    211                              (reg_t)operation,
    212                              (reg_t)value, 0, 0 );
    213 }
    214 
    215 ///////////////////////////////
    216 int chmod( char     * pathname,
    217            unsigned int   rights )
    218 {
    219     return hal_user_syscall( SYS_CHMOD,
    220                              (reg_t)pathname,
    221                              (reg_t)rights, 0, 0 );
    222 }
    223 
    224 /////////////////////////////////
    225 int signal( unsigned int   sigid,
    226             void         * handler )
    227 {
    228     return hal_user_syscall( SYS_SIGNAL,
    229                              (reg_t)sigid,
    230                              (reg_t)handler, 0, 0 );
    231 }
    232 
    233 ///////////////////////////////////////
    234 int gettimeofday( struct timeval  * tv,
    235                   struct timezone * tz )
    236 {
    237     return hal_user_syscall( SYS_SIGNAL,
    238                              (reg_t)tv,
    239                              (reg_t)tz, 0, 0 );
    240 }
    241 
    242 ///////////////////////////
    243 int kill( unsigned int pid,
    244           unsigned int sig_id )
    245 {
    246     return hal_user_syscall( SYS_KILL,
    247                              (reg_t)pid,
    248                              (reg_t)sig_id, 0, 0 );
    249 }
    250 
    251 ////////////
    252 int getpid()
    253 {
    254     return hal_user_syscall( SYS_GETPID, 0, 0, 0, 0 );
    255 }
    256 
    257 //////////
    258 int fork()
    259 {
    260     return hal_user_syscall( SYS_FORK, 0, 0, 0, 0 );
    261 }
    262 
    263 ///////////////////////////
    264 int exec( char  * pathname,
    265           char ** argv,
    266           char ** envp )
    267 {
    268     return hal_user_syscall( SYS_EXEC,
    269                              (reg_t)pathname,
    270                              (reg_t)argv,
    271                              (reg_t)envp, 0 );
    272 }
    273 
    274 /////////////////////////////////
    275 int stat( const char  * pathname,
    276           struct stat * stat )
    277 {
    278     return hal_user_syscall( SYS_STAT,
    279                              (reg_t)pathname,
    280                              (reg_t)stat, 0, 0 );
    281 }
    282 
    283 ////////////////////////
    284 int wait( int * status )
    285 {
    286     return hal_user_syscall( SYS_WAIT,
    287                              (reg_t)status, 0, 0, 0 );
    288 }
    289 
    290 
    291 
    292 /////////////     Non standard system calls ////////////////////////////////////
    293 
    294 
    295 //////////////////////////
    296 int fg( unsigned int pid )
    297 {
    298     return hal_user_syscall( SYS_FG,
    299                              (reg_t)pid, 0, 0, 0 );
    300 }
    301 
    302 //////////////////////////////////////
    303 int get_config( unsigned int * x_size,
    304                 unsigned int * y_size,
    305                 unsigned int * ncores )
    306 {
    307     return hal_user_syscall( SYS_GET_CONFIG,
    308                              (reg_t)x_size,
    309                              (reg_t)y_size,
    310                              (reg_t)ncores, 0 );
    311 }
    312 
    313 /////////////////////////////////
    314 int get_core( unsigned int * cxy,
    315               unsigned int * lid )
    316 {
    317     return hal_user_syscall( SYS_GET_CORE,
    318                              (reg_t)cxy,
    319                              (reg_t)lid, 0, 0 );
    320 }
    321 
    322 ////////////////////////////////////
    323 void display_string( char * string )
    324 {
    325     hal_user_syscall( SYS_DISPLAY,
    326                       DISPLAY_STRING,
    327                       (reg_t)string, 0, 0 );
    328 }
    329 
    330 //////////////////////////////////
    331 int display_vmm( unsigned int cxy,
    332                  unsigned int pid )
    333 {
    334     return hal_user_syscall( SYS_DISPLAY,
    335                              DISPLAY_VMM,
    336                              (reg_t)cxy,
    337                              (reg_t)pid, 0 );
    338 }
    339 
    340 ////////////////////////////////////
    341 int display_sched( unsigned int cxy,
    342                    unsigned int lid )
    343 {
    344     return hal_user_syscall( SYS_DISPLAY,
    345                              DISPLAY_SCHED,
    346                              (reg_t)cxy,
    347                              (reg_t)lid, 0 );
    348 }
    349 
    350 /////////////////////////////////////////////////
    351 int display_cluster_processes( unsigned int cxy )
    352 {
    353     return hal_user_syscall( SYS_DISPLAY,
    354                              DISPLAY_CLUSTER_PROCESSES,
    355                              (reg_t)cxy, 0, 0 );
    356 }
    357 
    358 ///////////////////
    359 int display_chdev()
    360 {
    361     return hal_user_syscall( SYS_DISPLAY,
    362                              DISPLAY_CHDEV, 0, 0, 0 );
    363 }
    364 
    365 /////////////////
    366 int display_vfs()
    367 {
    368     return hal_user_syscall( SYS_DISPLAY,
    369                              DISPLAY_VFS, 0, 0, 0 );
    370 }
    371 
    372 ////////////////////////////////////////////////
    373 int display_txt_processes( unsigned int txt_id )
    374 {
    375     return hal_user_syscall( SYS_DISPLAY,
    376                              DISPLAY_TXT_PROCESSES,
    377                              (reg_t)txt_id, 0, 0 );
    378 }
    379 
    380 ///////////////////////////////////////////
    381 int get_cycle( unsigned long long * cycle )
    382 {
    383     return hal_user_syscall( SYS_GET_CYCLE,
    384                              (reg_t)cycle, 0, 0, 0 );
    385 }
    386 
    387 ///////////////////////////////
    388 int trace( unsigned int active,
    389            unsigned int cxy,
    390            unsigned int lid )
    391 {
    392     return hal_user_syscall( SYS_TRACE,
    393                              (reg_t)active,
    394                              (reg_t)cxy,
    395                              (reg_t)lid, 0 );
    396 }
    397 
    398 
     312
     313
     314
     315
  • trunk/libs/mini-libc/stdio.h

    r443 r444  
    2525#define _STDIO_H_
    2626
    27 #include <shared_syscalls.h>
     27#include <almos-mkh/stdio.h>
    2828
    2929#define  NULL  (void *)0
     30/*********************************************************************************************
     31 * This function writes a formated string to the standard "stdout" stream.
     32 *********************************************************************************************
     33 * @ returns number of characters written if success / returns -1 if failure.
     34 ********************************************************************************************/
     35int printf( const char * format, ... );
    3036
    31 /****************** Standard (POSIX) system calls  **************************************/
     37/*********************************************************************************************
     38 * This function writes one single character to the standard "stdout" stream.
     39 *********************************************************************************************
     40 * @ returns written character code if success / returns 0 (EOF) if failure.
     41 ********************************************************************************************/
     42int putchar( int c );
    3243
    33 /***************************************************************************************** 
    34  * This function terminates a process.
    35  *****************************************************************************************
    36  * @ status   : terminaison status : 0 / EXIT_SUCCESS / EXIT_FAILURE.
    37  ****************************************************************************************/
    38 void exit( int status );
     44/*********************************************************************************************
     45 * This function returns one single character from the standard "stdin" stream.
     46 *********************************************************************************************
     47 * @ returns read character code if success / returns 0 (EOF) if failure.
     48 ********************************************************************************************/
     49int getchar();
    3950
    40 /*****************************************************************************************
    41  * This function open or create an open file descriptor.
    42  *****************************************************************************************
    43  * @ pathname   : pathname (can be relative or absolute).
    44  * @ flags      : bit vector attributes (see syscalls).
    45  * @ mode       : access rights (if O_CREAT is set).
    46  * @ return file descriptor index in fd_array if success / return -1 if failure.
    47  ****************************************************************************************/
    48 int open( const char * pathname,
    49           int          flags,
    50           int          mode );
    51 
    52 /*****************************************************************************************
    53  * This function map physical memory (or a file) in the calling thread virtual space.
    54  *****************************************************************************************
    55  * @ addr       : unused and unsupported : must be NULL.
    56  * @ length     : requested number of bytes.
    57  * @ prot       : RWX access modes.
    58  * @ flags      : MAP_FILE / MAP_ANON / MAP_PRIVATE / MAP_SHARED (defined in syscalls.h) 
    59  * @ fdid       : file descriptor index (if MAP_FILE).                     
    60  * @ offset         : offset in file (if MAP_FILE)
    61  * @ return 0 if success / return -1 if failure.
    62  ****************************************************************************************/
    63 void * mmap( void         * addr,
    64              unsigned int   length,
    65              int            prot,
    66              int            flags,
    67              int            fd,
    68              unsigned int   offset );
    69 
    70 /*****************************************************************************************
    71  * This function read bytes from an open file identified by its file descriptor.
    72  * This file can be a regular file or a character oriented device.
    73  *****************************************************************************************
    74  * @ file_id  : open file index in fd_array.
    75  * @ buf      : buffer virtual address in user space.
    76  * @ count    : number of bytes.
    77  * @ return number of bytes actually read if success / returns -1 if failure.
    78  ****************************************************************************************/
    79 int read( int            fd,
    80           void         * buf,
    81           unsigned int   count );
    82 
    83 /*****************************************************************************************
    84  * This function writes bytes to an open file identified by its file descriptor.
    85  * This file can be a regular file or character oriented device.
    86  *****************************************************************************************
    87  * @ file_id  : open file index in fd_array.
    88  * @ buf      : buffer virtual address in user space.
    89  * @ count    : number of bytes.
    90  * @ return number of bytes actually written if success / returns -1 if failure.
    91  ****************************************************************************************/
    92 int write( int            fd,
    93            const void   * buf,
    94            unsigned int   count );
    95 
    96 /*****************************************************************************************
    97  * This function repositions the offset of the file descriptor identified by <file_id>,
    98  * according to the operation type defined by the <whence> argument.
    99  *****************************************************************************************
    100  * @ fd       : open file index in fd_array.
    101  * @ offset   : used to compute new offset value.
    102  * @ whence   : operation type (SEEK_SET / SEEK_CUR / SEEK_END defined in syscalls.h)
    103  * @ return 0 if success / returns -1 if failure.
    104  ****************************************************************************************/
    105 int lseek( int           fd,
    106            unsigned int  offset,
    107            int           whence );
    108 
    109 /*****************************************************************************************
    110  * This function release the memory allocated for the file descriptor identified by
    111  * the <file_id> argument, and remove the fd array_entry in all copies of the process
    112  * descriptor.
    113  *****************************************************************************************
    114  * fd   : file descriptor index in fd_array.
    115  * @ return 0 if success / returns -1 if failure.
    116  ****************************************************************************************/
    117 int close( int fd );
    118 
    119 /*****************************************************************************************
    120  * This function removes a directory entry identified by the <pathname> from the
    121  * directory, and decrement the link count of the file referenced by the link.
    122  * If the link count reduces to zero, and no process has the file open, then all resources
    123  * associated with the file are released.  If one or more process have the file open when
    124  * the last link is removed, the link is removed, but the removal of the file is delayed
    125  * until all references to it have been closed.
    126  *****************************************************************************************
    127  * @ pathname   : pathname (can be relative or absolute).
    128  * @ return 0 if success / returns -1 if failure.
    129  ****************************************************************************************/
    130 int unlink( const char * pathname );
    131 
    132 /*****************************************************************************************
    133  * This function creates in the calling thread cluster an unnamed pipe, and two
    134  * (read and write) file descriptors to access this pipe. The calling function must pass
    135  * the pointer on the fd[] array.
    136  * TODO not implemented yet...
    137  *****************************************************************************************
    138  * @ file_id[0] : [out] read only file descriptor index.
    139  * @ file_id[1] : [out] write only file descriptor index.
    140  * @ return 0 if success / return -1 if failure.
    141  ****************************************************************************************/
    142 int pipe( int fd[2] );
    143 
    144 /*****************************************************************************************
    145  * This function change the current working directory in reference process descriptor.
    146  *****************************************************************************************
    147  * @ pathname   : pathname (can be relative or absolute).
    148  * @ return 0 if success / returns -1 if failure.
    149  ****************************************************************************************/
    150 int chdir( const char * pathname );
    151 
    152 /*****************************************************************************************
    153  * This function creates a new directory in file system.
    154  *****************************************************************************************
    155  * @ pathname   : pathname (can be relative or absolute).
    156  * @ mode       : access rights (as defined in chmod).
    157  * @ return 0 if success / returns -1 if failure.
    158  ****************************************************************************************/
    159 int mkdir( const char * pathname,
    160            int          mode );
    161 
    162 /*****************************************************************************************
    163  * This function creates a named FIFO file in the calling thread cluster.
    164  * The associated read and write file descriptors mut be be  explicitely created
    165  * using the open() system call.
    166  *****************************************************************************************
    167  * @ pathname   : pathname (can be relative or absolute).
    168  * @ mode       : access rights (as defined in chmod).
    169  * @ return 0 if success / returns -1 if failure.
    170  ****************************************************************************************/
    171 int mkfifo( const char * pathname,
    172             int          mode );
    173 
    174 /*****************************************************************************************
    175  * This function opens the directory identified by the <pathname> argument,
    176  * associates a directory stream with it and returns an user space pointer to identify
    177  * this directory stream in subsequent operations. 
    178  *****************************************************************************************
    179  * @ pathname   : pathname (can be relative or absolute).
    180  * @ returns DIR* pointer if success / returns NULL if pathname cannot be accessed.
    181  ****************************************************************************************/
    182 DIR * opendir( const char * pathname );
    183 
    184 /*****************************************************************************************
    185  * This function returns a pointer to the next directory entry.
    186  *****************************************************************************************
    187  * @ dirp     : DIR pointer identifying the directory.
    188  * @ returns dirent* pointer / returns NULL upon reaching end of directory or on error.
    189  ****************************************************************************************/
    190 struct dirent * readdir( DIR * dirp );
    191 
    192 /*****************************************************************************************
    193  * This function closes the directory identified by the <dirp> argument, and releases
    194  * all structures associated with the <dirp> pointer.
    195  *****************************************************************************************
    196  * @ dirp     : DIR pointer identifying the directory.
    197  * @ returns 0 if success / returns -1 if failure.
    198  ****************************************************************************************/
    199 int closedir( DIR * dirp );
    200 
    201 /*****************************************************************************************
    202  * This function returns the pathname of the current working directory.
    203  *****************************************************************************************
    204  * buf     : buffer addres in user space.
    205  * nbytes  : user buffer size in bytes.
    206  * @ return 0 if success / returns -1 if failure.
    207  ****************************************************************************************/
    208 int getcwd( char       * buf,
    209             unsigned int nbytes );
    210 
    211 /*****************************************************************************************
    212  * This function removes a directory file whose name is given by <pathname>.
    213  * The directory must not have any entries other than `.' and `..'.
    214  *****************************************************************************************
    215  * @ pathname   : pathname (can be relative or absolute).
    216  * @ return 0 if success / returns -1 if failure.
    217  ****************************************************************************************/
    218 int rmdir( char * pathname );
    219 
    220 /*****************************************************************************************
    221  * This function implement the operations related to User Thread Local Storage.
    222  *****************************************************************************************
    223  * @ operation  : UTLS operation type as defined in "shared_sycalls.h" file.
    224  * @ value      : argument value for the UTLS_SET operation.
    225  * @ return value for the UTLS_GET and UTLS_GET_ERRNO / return -1 if failure.
    226  ****************************************************************************************/
    227 int utls( unsigned int operation,
    228           unsigned int value );
    229 
    230 /*****************************************************************************************
    231  * This function change the acces rights for the file/dir identified by the
    232  * pathname argument.
    233  *****************************************************************************************
    234  * @ pathname   : pathname (can be relative or absolute).
    235  * @ rights     : acces rights.
    236  * @ return 0 if success / returns -1 if failure.
    237  ****************************************************************************************/
    238 int chmod( char     * pathname,
    239            unsigned int   rights );
    240 
    241 /*****************************************************************************************
    242  * This function associate a specific signal handler to a given signal type.
    243  * The handlers for the SIGKILL and SIGSTOP signals cannot be redefined.
    244  *****************************************************************************************
    245  * @ sig_id    : index defining signal type (from 1 to 31).
    246  * @ handler   : pointer on fonction implementing the specific handler.
    247  * @ return 0 if success / returns -1 if failure.
    248  ****************************************************************************************/
    249 int signal( unsigned int   sig_id,
    250             void         * handler );
    251 
    252 /*****************************************************************************************
    253  * This function returns in the structure <tv>, defined in the time.h file,
    254  * the current time (in seconds & micro-seconds).
    255  * It is computed from the calling core descriptor.
    256  * The timezone is not supported.
    257  *****************************************************************************************
    258  * @ tv      : pointer on the timeval structure.
    259  * @ tz      : pointer on the timezone structure : must be NULL.       
    260  * @ return 0 if success / returns -1 if failure.
    261  ****************************************************************************************/
    262 int gettimeofday( struct timeval  * tv,
    263                   struct timezone * tz );
    264 
    265 /*****************************************************************************************
    266  * This function implements the "kill" system call on the user side.
    267  * It register the signal defined by the <sig_id> argument in all thread descriptors
    268  * of a target process identified by the <pid> argument. This is done in all clusters
    269  * containing threads for the target process.
    270  * It can be executed by any thread running in any cluster, as this function uses
    271  * remote access to traverse the list of process copies stored in the owner cluster,
    272  * and the RPC_SIGNAL_RISE to signal the remote threads.
    273  * This function does nothing for (sig_id == 0). This can be used to check process pid.
    274  * TODO : This first implementation supports only SIGKILL / SIGSTOP / SIGCONT values.
    275  *****************************************************************************************
    276  * @ pid      : target process identifier.
    277  * @ sig_id   : index defining the signal type.
    278  * @ return 0 if success / returns -1 if failure.
    279  ****************************************************************************************/
    280 int kill( unsigned int  pid,
    281           unsigned int  sig_id );
    282 
    283 /*****************************************************************************************
    284  * This function implements the "getpid" system call on the user side.
    285  *****************************************************************************************
    286  * @ returns the process PID for the calling thread process.
    287  ****************************************************************************************/
    288 int getpid();
    289 
    290 /*****************************************************************************************
    291  * This function implement the "fork" system call on the user side.
    292  * The calling process descriptor (parent process), and the associated thread descriptor
    293  * are replicated in a - likely - remote cluster, that becomes the new process owner.
    294  * The child process get a new PID is linked to the parent PID. The child process inherit
    295  * from the parent process the memory image, and all open files (including the TXT).
    296  * The child process becomes the TXT terminal owner.
    297  * The target cluster depends on the "fork_user" flag and "fork_cxy" variable that can be
    298  * stored in the calling thread descriptor by the specific fork_place() system call.
    299  * If not, the kernel function makes a query to the DQDT to select the target cluster.
    300  *****************************************************************************************
    301  * @ if success, returns child process PID to parent, and return O to child.
    302  * @ if failure, returns -1 to parent / no child process is created.
    303  ****************************************************************************************/
    304 int fork();
    305 
    306 /*****************************************************************************************
    307  * This function implement the "exec" system call on the user side.
    308  * It creates, in the same cluster as the calling thread, a new process descriptor,
    309  * and a new associated main thread descriptor, executing a new memory image defined
    310  * by the <filename> argument. This new process inherit from the old process the PID
    311  * and the PPID, as well as all open files (including the TXT).
    312  * The old process descriptor, and all its threads are blocked, and marked for deletion.
    313  * Therefore the exec syscall does not return to the calling thread in case of success.
    314  * This function build an exec_info_t structure containing the new process arguments,
    315  * as defined by the <arv> argument, and the new process environment variables,
    316  * as defined by the <envp>  argument.
    317  * TODO : the <argv> and <envp> arguments are not supported yet (both must be NULL).
    318  *****************************************************************************************
    319  * @ filename : string pointer on .elf filename (virtual pointer in user space)
    320  * @ argv     : array of strings on process arguments (virtual pointers in user space)
    321  * @ envp     : array of strings on environment variables (virtual pointers in user space)
    322  * @ does not return if success / returns -1 if failure.
    323  ****************************************************************************************/
    324 int exec( char  * filename,
    325           char ** argv,
    326           char ** envp );
    327 
    328 /*****************************************************************************************
    329  * This function  returns in the <stat> structure, defined in the "shared_syscalls.h"
    330  * file, various informations on the file/directory identified by the <pathname> argument.
    331  *****************************************************************************************
    332  * @ pathname  : user pointer on file pathname.
    333  * @ stat      : user pointer on the stat structure.
    334  * @ returns O if success / returns -1 if failure.
    335  ****************************************************************************************/
    336 int stat( const char  * pathname,
    337           struct stat * stat );
    338 
    339 /*****************************************************************************************
    340  * This blocking function returns only when one child process of the calling process
    341  * changes state (from RUNNING to STOPPED / EXITED / KILLED). It returns the terminating
    342  * child process PID, and set in the <status> buffer the new child process state.
    343  *****************************************************************************************
    344  * @ status    : [out] terminating child process state.
    345  * @ returns terminating child process pid.
    346  ****************************************************************************************/
    347 int wait( int * status );
    348 
    349 
    350 /****************** Non standard (ALMOS_MKH specific) system calls **********************/
    351 
    352 
    353 /*****************************************************************************************
    354  * This function is used to give the process identified by the <pid> argument the
    355  * exclusive ownership of the attached TXT_RX terminal.
    356  *****************************************************************************************
    357  * @ pid        : process identifier.
    358  * @ returns O if success / returns -1 if process not found.
    359  ****************************************************************************************/
    360 int fg( unsigned int pid );
    361 
    362 /***************************************************************************************
    363  * This function returns the hardware platform parameters.
    364  ***************************************************************************************
    365  * @ x_size   : [out] number of clusters in a row.
    366  * @ y_size   : [out] number of clusters in a column.
    367  * @ ncores   : [out] number of cores per cluster.
    368  * @ return always 0.
    369  **************************************************************************************/
    370 int get_config( unsigned int * x_size,
    371                 unsigned int * y_size,
    372                 unsigned int * ncores );
    373 
    374 /***************************************************************************************
    375  * This function returns the cluster an local index for the calling core.
    376  ***************************************************************************************
    377  * @ cxy      : [out] cluster identifier.
    378  * @ lid      : [out] core local index in cluster.
    379  * @ return always 0.
    380  **************************************************************************************/
    381 int get_core( unsigned int * cxy,
    382               unsigned int * lid );
    383 
    384 /***************************************************************************************
    385  * This function returns the calling core cycles counter,
    386  * taking into account a possible overflow on 32 bits architectures.
    387  ***************************************************************************************
    388  * @ cycle    : [out] current cycle value.
    389  * @ return always 0.
    390  **************************************************************************************/
    391 int get_cycle( unsigned long long * cycle );
    392 
    393 /***************************************************************************************
    394  * This debug function displays on the kernel terminal TXT0
    395  * the thread / process / core identifiers, the current cycle, plus a user defined
    396  * message as specified by the <string> argument.
    397  ***************************************************************************************
    398  * @ string    : [in] user defined message.
    399  **************************************************************************************/
    400 void display_string( char * string );
    401 
    402 /***************************************************************************************
    403  * This debug function displays on the kernel terminal TXT0
    404  * the state of the VMM forthe process <pid>, in cluster <cxy>.
    405  * It can be called by any thread running in any cluster.
    406  ***************************************************************************************
    407  * @ pid      : [in] process identifier.
    408  * @ return 0 if success / return -1 if illegal argument.
    409  **************************************************************************************/
    410 int display_vmm( unsigned int  cxy,
    411                  unsigned int  pid );
    412 
    413 /***************************************************************************************
    414  * This debug function displays on the kernel terminal TXT0
    415  * the state of the core scheduler identified by the <cxy> and <lid> arguments.
    416  * It can be called by any thread running in any cluster.
    417  ***************************************************************************************
    418  * @ cxy      : [in] target cluster identifier.
    419  * @ lid      : [in] target core local index.
    420  * @ return 0 if success / return -1 if illegal arguments.
    421  **************************************************************************************/
    422 int display_sched( unsigned int  cxy,
    423                    unsigned int  lid );
    424 
    425 /***************************************************************************************
    426  * This debug function displays on the kernel terminal TXT0
    427  * the list of process registered in a given cluster identified by the <cxy> argument.
    428  * It can be called by any thread running in any cluster.
    429  ***************************************************************************************
    430  * @ cxy      : [in] target cluster identifier.
    431  * @ return 0 if success / return -1 if illegal argument.
    432  **************************************************************************************/
    433 int display_cluster_processes( unsigned int  cxy );
    434 
    435 /***************************************************************************************
    436  * This debug function displays on the kernel terminal TXT0
    437  * the list of channel devices available in the architecture.
    438  * It can be called by any thread running in any cluster.
    439  ***************************************************************************************
    440  * @ return always 0.
    441  **************************************************************************************/
    442 int display_chdev();
    443 
    444 /***************************************************************************************
    445  * This debug function displays on the kernel terminal TXT0
    446  * the list of channel device or pseudo-files registered in the VFS cache.
    447  * It can be called by any thread running in any cluster.
    448  ***************************************************************************************
    449  * @ return always 0.
    450  **************************************************************************************/
    451 int display_vfs();
    452 
    453 /***************************************************************************************
    454  * This debug function displays on the kernel terminal TXT0
    455  * the list of processes attached to a given TXT channel.
    456  * It can be called by any thread running in any cluster.
    457  ***************************************************************************************
    458  * @ return always 0.
    459  **************************************************************************************/
    460 int display_txt_processes( unsigned int txt_id );
    461 
    462 /*****************************************************************************************
    463  * This debug function is used to activate / desactivate the context switches trace
    464  * for a core identified by the <cxy> and <lid> arguments.
    465  * It can be called by any thread running in any cluster.
    466  *****************************************************************************************
    467  * @ active     : activate trace if non zero / desactivate if zero.
    468  * @ cxy        : cluster identifier.
    469  * @ lid        : core local index.
    470  * @ returns O if success / returns -1 if illegal arguments.
    471  ****************************************************************************************/
    472 int trace( unsigned int active,
    473            unsigned int cxy,
    474            unsigned int lid );
    475 
     51/*********************************************************************************************
     52 * This function copies a formated string to a fixed size buffer.
     53 * it includes the NUL terminating character.
     54 * it cheks that the formated string fit in the buffer length.
     55 *********************************************************************************************
     56 * @ string    :  pointer on target buffer.
     57 * @ length    : max bumber of characters in target buffer.
     58 * @ format    : formated string.
     59 * @ returns number of characters written if success / returns -1 if failure.
     60 ********************************************************************************************/
     61int snprintf( char         * string,
     62              unsigned int   length,
     63              const char   * format, ... );
    47664
    47765#endif  // _STDIO_H_
  • trunk/libs/mini-libc/stdlib.c

    r443 r444  
    2222 */
    2323
     24#include <stdlib.h>
    2425#include <stdio.h>
    25 #include <stdarg.h>
    26 #include <pthread.h>
    27 #include <stdlib.h>
    28 
    29 /////////////////////////////
    30 void assert( int expression )
    31 {
    32     if( expression == 0 )
    33     {
    34         printf("\n[ASSERT FAILED] in %s at line %d in file %s\n",
    35         __FUNCTION__ , __LINE__ , __FILE__ );
    36 
    37         exit( 0 );
    38     }
    39 }
    40 
     26#include <almos-mkh.h>
     27#include <hal_user.h>
     28#include <syscalls_numbers.h>
     29
     30#define  reg_t     int
    4131//////////////////////////
    4232int atoi(const char * str)
     
    124114}
    125115
    126 ///////////////////////////////////////////////////////////////
    127 void * memcpy(void *_dst, const void * _src, unsigned int size)
    128 {
    129     unsigned int * dst = _dst;
    130     const unsigned int * src = _src;
    131     if (!((unsigned int) dst & 3) && !((unsigned int) src & 3) )
    132     {
    133         while (size > 3)
    134         {
    135             *dst++ = *src++;
    136             size -= 4;
    137         }
    138     }
    139 
    140     unsigned char *cdst = (unsigned char*)dst;
    141     unsigned char *csrc = (unsigned char*)src;
    142 
    143     while (size--)
    144     {
    145         *cdst++ = *csrc++;
    146     }
    147     return _dst;
    148 }
    149 
    150 //////////////////////////////////////////////////////////
    151 inline void * memset(void * dst, int s, unsigned int size)
    152 {
    153     char * a = (char *) dst;
    154     while (size--)
    155     {
    156         *a++ = (char)s;
    157     }
    158     return dst;
    159 }
    160 
    161 
    162 //////////////////////////////////////////
    163 static int xprintf( char         * string,
    164                     unsigned int   length,
    165                     const char   * format,
    166                     va_list      * args )
    167 {
    168     unsigned int ps = 0;    // write index to the string buffer
    169 
    170 #define TO_STREAM(x) do { string[ps] = (x); ps++; if(ps==length) return -1; } while(0);
    171 
    172 xprintf_text:
    173 
    174     while ( *format != 0 )
    175     {
    176 
    177         if (*format == '%')   // copy argument to string
    178         {
    179             format++;
    180             goto xprintf_arguments;
    181         }
    182         else                  // copy one char to string
    183         {
    184             TO_STREAM( *format );
    185             format++;
    186         }
    187     }
    188 
    189     return ps;
    190 
    191 xprintf_arguments:
    192 
    193     {
    194         char              buf[30];    // buffer to display one number
    195         char *            pbuf;       // pointer on first char to display
    196         unsigned int      len = 0;    // number of char to display
    197         static const char HexaTab[] = "0123456789ABCDEF";
    198         unsigned int      i;
    199        
    200         // Ignore fields width and precision
    201         for ( ; (*format >= '0' && *format <= '9') || (*format == '.') ; format++ );
    202 
    203         switch (*format)
    204         {
    205             case ('c'):             // char conversion
    206             {
    207                 int val = va_arg( *args, int );
    208                 buf[0] = val;
    209                 pbuf   = buf;
    210                 len    = 1;
    211                 break;
    212             }
    213             case ('d'):             // decimal signed integer
    214             {
    215                 int val = va_arg( *args, int );
    216                 if (val < 0)
    217                 {
    218                     TO_STREAM( '-' );
    219                     val = -val;
    220                 }
    221                 for(i = 0; i < 10; i++)
    222                 {
    223 
    224                     buf[9 - i] = HexaTab[val % 10];
    225                     if (!(val /= 10)) break;
    226                 }
    227                 len =  i + 1;
    228                 pbuf = &buf[9 - i];
    229                 break;
    230             }
    231             case ('u'):             // decimal unsigned integer
    232             {
    233                 unsigned int val = va_arg( *args, unsigned int );
    234                 for(i = 0; i < 10; i++)
    235                 {
    236                     buf[9 - i] = HexaTab[val % 10];
    237                     if (!(val /= 10)) break;
    238                 }
    239                 len =  i + 1;
    240                 pbuf = &buf[9 - i];
    241                 break;
    242             }
    243             case ('x'):             // 32 bits hexadecimal
    244             case ('l'):             // 64 bits hexadecimal
    245             {
    246                 unsigned int       imax;
    247                 unsigned long long val;
    248                
    249                 if ( *format == 'l' )   // 64 bits
    250                 {
    251                     val = va_arg( *args, unsigned long long);
    252                     imax = 16;
    253                 }
    254                 else                    // 32 bits
    255                 {
    256                     val = va_arg( *args, unsigned int);
    257                     imax = 8;
    258                 }
    259                
    260                 TO_STREAM( '0' );
    261                 TO_STREAM( 'x' );
    262                
    263                 for(i = 0; i < imax; i++)
    264                 {
    265                     buf[(imax-1) - i] = HexaTab[val % 16];
    266                     if (!(val /= 16))  break;
    267                 }
    268                 len =  i + 1;
    269                 pbuf = &buf[(imax-1) - i];
    270                 break;
    271             }
    272             case ('s'):             /* string */
    273             {
    274                 char* str = va_arg( *args, char* );
    275                 while (str[len]) { len++; }
    276                 pbuf = str;
    277                 break;
    278             }
    279 /*
    280             case ('f'):             // IEEE754 64 bits
    281                                     // integer part : up to 10 decimal digits
    282                                     // decimal part : 9 decimal digits
    283             {
    284                 union
    285                 {
    286                     double d;
    287                     unsigned long long ull;
    288                 } val;
    289                
    290                 val.d = va_arg( *args, double );
    291                
    292                 unsigned long long mantisse;
    293                 mantisse = val.ull & 0xFFFFFFFFFFFFFULL;    // mantisse
    294                
    295                 unsigned int exp;
    296                 exp = (unsigned int)((val.ull & 0x7FF0000000000000ULL) >> 52); // exp
    297 
    298                 if (exp == 0x7FF) // special values
    299                 {
    300                     if (mantisse & 0xFFFFFFFFFFFFFULL)  // Not a Number
    301                     {
    302                         buf[0] = 'N';
    303                         buf[1] = 'a';
    304                         buf[2] = 'N';
    305                         len = 3;
    306                         pbuf = buf;
    307                     }
    308                     else                              // infinite
    309                     {
    310                         // inf
    311                         buf[0] = (val.ull & 0x8000000000000000ULL) ? '-' : '+';
    312                         buf[1] = 'i';
    313                         buf[2] = 'n';
    314                         buf[3] = 'f';
    315                         len = 4;
    316                         pbuf = buf;
    317                     }
    318                     break;
    319                 }
    320 
    321                 // display sign & analyse overflow
    322                 unsigned int overflow = 0;
    323                 if (val.ull & 0x8000000000000000ULL)  // negative
    324                 {
    325                     TO_STREAM( '-' );
    326                     val.d = val.d * -1;
    327                     if( val.d < -9999999999.0) overflow = 1;
    328                 }
    329                 else                                  // positive
    330                 {
    331                     TO_STREAM( '+' );
    332                     if( val.d > 9999999999.0) overflow = 1;
    333                 }
    334                
    335                 // check overflow caused by the 10.9 format
    336                 if ( overflow )   
    337                 {
    338                     buf[0] = 'o';
    339                     buf[1] = 'v';
    340                     buf[2] = 'r';
    341                     len = 3;
    342                     pbuf = buf;
    343                     break;
    344                 }
    345 
    346                 // compute integer & decimal parts
    347                 unsigned int intp;                  // integer part
    348                 unsigned int decp;                  // decimal part
    349                 intp = (unsigned int)val.d;     
    350                 val.d -= (double)intp;
    351                 decp = (unsigned int)(val.d * 1000000000);
    352                
    353                 // display decimal value in 10.9 format
    354                 for(i = 0; i < 10; i++)
    355                 {
    356                     buf[9 - i] = HexaTab[intp % 10];
    357                     if (!(intp /= 10)) break;
    358                 }
    359                 pbuf = &buf[9 - i];
    360                 len = i+11;
    361                 buf[10] = '.';
    362                 for(i = 0; i < 9; i++)
    363                 {
    364                     buf[19 - i] = HexaTab[decp % 10];
    365                     decp /= 10;
    366                 }
    367                 break;
    368             }
    369 */                   
    370             default:       // unsupported argument type
    371             {
    372                 return -1;
    373             }
    374         }  // end switch on  argument type
    375 
    376         format++;
    377 
    378         // copy argument to string
    379         for( i = 0 ; i < len ; i++ )
    380         {
    381             TO_STREAM( pbuf[i] );
    382         }
    383        
    384         goto xprintf_text;
    385     }
    386 } // end xprintf()
    387 
    388 //////////////////////////////////////
    389 int printf( const char * format, ... )
    390 {
    391     char      string[4096];
    392     va_list   args;
    393     int       count;
    394    
    395     va_start( args, format );
    396     count = xprintf( string , 4095 , format , &args );
    397     va_end( args );
    398 
    399     if ( count == -1 )
    400     {
    401         display_string( "stdlib : xprintf failure" );
    402         return -1;
    403     }
    404     else
    405     {
    406         string[count] = 0;
    407         return write( 1 , &string , count + 1 );
    408     }
    409 }
    410 
    411 /////////////
    412 int getchar()
    413 {
    414     char byte;
    415 
    416     if ( read( 0 , &byte , 1 ) != 1 ) return 0;
    417     else                              return (int)byte;
    418 }
    419 
    420 ////////////////////
    421 int putchar( int c )
    422 {
    423     char byte = (char)c;
    424 
    425     if( write( 1 , &byte , 1 ) != 1 ) return 0;
    426     else                              return c;
    427 }
    428 
    429 ////////////
    430 int getint()
    431 {
    432     unsigned int  i;
    433     int           val;    // ASCII character value
    434 
    435     unsigned char buf[32];
    436     unsigned int  save          = 0;
    437     unsigned int  dec           = 0;
    438     unsigned int  done          = 0;
    439     unsigned int  overflow      = 0;
    440     unsigned int  length        = 0;
    441  
    442     // get characters
    443     while (done == 0)
    444     {
    445         // read one character
    446         val = getchar();
    447 
    448         // analyse character
    449         if ((val > 0x2F) && (val < 0x3A))         // decimal character
    450         {
    451             buf[length] = (unsigned char)val;
    452             length++;                     
    453             putchar( val );                       // echo
    454         }
    455         else if (val == 0x0A)                     // LF character
    456         {
    457             done = 1;
    458         }
    459         else if ( (val == 0x7F) ||                // DEL character
    460                   (val == 0x08) )                 // BS  character
    461         {
    462             if ( length > 0 )
    463             {
    464                 length--;         
    465                 printf("\b \b");                  // BS /  / BS
    466             }
    467         }
    468         else if ( val == 0 )                      // EOF
    469         {
    470             return -1;
    471         }
    472 
    473         // test buffer overflow
    474         if ( length >= 32 ) 
    475         {
    476             overflow = 1;
    477             done     = 1;
    478         }
    479     }  // end while characters
    480 
    481     // string to int conversion with overflow detection
    482     if ( overflow == 0 )
    483     {
    484         for (i = 0; (i < length) && (overflow == 0) ; i++)
    485         {
    486             dec = dec * 10 + (buf[i] - 0x30);
    487             if (dec < save)  overflow = 1;
    488             save = dec;
    489         }
    490     }
    491 
    492     // final evaluation
    493     if ( overflow == 0 )
    494     {
    495         // return value
    496         return dec;
    497     }
    498     else
    499     {
    500         // cancel all echo characters
    501         for (i = 0; i < length ; i++)
    502         {
    503             printf("\b \b");                  // BS /  / BS
    504         }
    505 
    506         // echo character '0'
    507         putchar( '0' );
    508 
    509         // return 0 value
    510         return 0;
    511     }
    512 }  // end getint()
    513 
    514 ///////////////////////////////////////
    515 int snprintf( char           * string,
    516               unsigned int     length,
    517               const char     * format, ... )
    518 {
    519     va_list   args;
    520     int       count;
    521 
    522     va_start( args, format );
    523     count = xprintf( string , length , format , &args );
    524     va_end( args );
    525 
    526     if( count < length ) string[count] = 0;
    527 
    528     return count;
    529 }
     116
    530117
    531118//////////
     
    554141}
    555142
    556 ///////////
    557 void idbg()
    558 {
    559    char          cmd;
    560    unsigned int  cxy;
    561    unsigned int  lid;
    562    unsigned int  txt;
    563    unsigned int  active;
    564 
    565    while( 1 )
    566    {
    567         printf("\n[idbg] cmd = ");
    568         cmd = (char)getchar();
    569 
    570         if( cmd == 'h' )
    571         {
    572             printf("h\n"
    573                    "p : display on TXT0 process descriptors in cluster[cxy]\n"
    574                    "s : display on TXT0 scheduler state for core[cxy,lid]\n"
    575                    "v : display on TXT0 VMM for calling process in cluster [cxy]\n"
    576                    "t : display on TXT0 process decriptors attached to TXT[tid]\n"
    577                    "y : activate/desactivate trace for core[cxy,lid]\n"
    578                    "x : force calling process to exit\n"
    579                    "c : resume calling process execution\n"
    580                    "h : list supported commands\n");
    581         }
    582         else if( cmd == 'p' )
    583         {
    584             printf("p / cxy = ");
    585             cxy = getint();
    586             display_cluster_processes( cxy );
    587         }
    588         else if( cmd == 's' )
    589         {
    590             printf("s / cxy = ");
    591             cxy = getint();
    592             printf(" / lid = ");
    593             lid = getint();
    594             display_sched( cxy , lid );
    595         }
    596         else if( cmd == 'v' )
    597         {
    598             printf("v / cxy = ");
    599             cxy = getint();
    600             display_vmm( cxy , (unsigned int)getpid() );
    601         }
    602         else if( cmd == 't' )
    603         {
    604             printf("t / txt_id = ");
    605             txt = getint();
    606             display_txt_processes( txt );
    607         }
    608         else if( cmd == 'y' )
    609         {
    610             printf("y / active = ");
    611             active = getint();
    612             printf(" / cxy = ");
    613             cxy    = getint();
    614             printf(" / lid = ");
    615             lid    = getint();
    616             trace( active , cxy , lid );
    617         }
    618         else if( cmd == 'x' )
    619         {
    620             printf("x\n");
    621             exit( 0 );
    622         }
    623         else if( cmd == 'c' )
    624         {
    625             printf("c\n");
    626             break;
    627         }
    628     }
    629 }  // end idbg()
    630 
    631 
    632 
     143
     144
     145
     146//////////////////////////////////
     147void * malloc( unsigned int size )
     148{
     149    // get cluster identifier
     150    unsigned int cxy;
     151    unsigned int lid;
     152    get_core( &cxy , &lid );
     153
     154    return remote_malloc( size, cxy );
     155}
     156
     157
     158
     159///////////////////////////////////
     160void * calloc ( unsigned int count,
     161                unsigned int size )
     162{
     163    // get calling core cluster identifier
     164    unsigned int cxy;
     165    unsigned int lid;
     166    get_core( &cxy , &lid );
     167
     168    return remote_calloc( count , size , cxy );
     169}
     170
     171///////////////////////////////////
     172void * realloc ( void        * ptr,
     173                 unsigned int  size )
     174{
     175    // get calling core cluster identifier
     176    unsigned int cxy;
     177    unsigned int lid;
     178    get_core( &cxy , &lid );
     179
     180    return remote_realloc( ptr , size , cxy );
     181}
     182
     183///////////////////////
     184void free( void * ptr )
     185{
     186    // get calling core cluster identifier
     187    unsigned int cxy;
     188    unsigned int lid;
     189    get_core( &cxy , &lid );
     190
     191    remote_free( ptr , cxy );
     192}
     193
     194///////////////////////
     195void exit( int status )
     196{
     197    hal_user_syscall( SYS_EXIT,
     198                      (reg_t)status, 0, 0, 0 );
     199}
     200
     201
  • trunk/libs/mini-libc/stdlib.h

    r443 r444  
    2525#define _STDLIB_H
    2626
    27 #define   RAND_MAX   65535
    28  
    29 /*********************************************************************************************
    30  * This function tests the <expression> argument value.
    31  * When the value is false, it displays an error message, and terminates the calling thread.
    32  *********************************************************************************************
    33  * @ expression : Boolean expression to be checked.
    34  ********************************************************************************************/
    35 void assert( int expression );
     27#include <almos-mkh/stdlib.h>
     28
     29/***************************************************************************************** 
     30 * This function terminates a process.
     31 *****************************************************************************************
     32 * @ status   : terminaison status : 0 / EXIT_SUCCESS / EXIT_FAILURE.
     33 ****************************************************************************************/
     34void exit( int status );
     35
    3636
    3737/*********************************************************************************************
     
    4646 ********************************************************************************************/
    4747double atof(const char *str);
    48 
    49 /*********************************************************************************************
    50  * This function copies the content of a <src> byte array to a <dst> byte array.
    51  * Behaviour is undefined if <src> and <dst> arrays overlap.
    52  *********************************************************************************************
    53  * @ dst     : pointer on destination array.
    54  * @ dst     : pointer on source array.
    55  * @ size    : number of bytes to move.
    56  * @ return first argument.
    57  ********************************************************************************************/
    58 void * memcpy( void         * dst,
    59                const void   * src,
    60                unsigned int   size );
    61 
    62 /*********************************************************************************************
    63  * This function fill a byte array with a byte value.
    64  *********************************************************************************************
    65  * @ dst     : pointer on the byte array.
    66  * @ s       : byte value (will be casted to unsigned char).
    67  * @ size    : number of bytes to be set.
    68  * @ return first argument.
    69  ********************************************************************************************/
    70 void * memset( void        * dst,
    71                int           s,
    72                unsigned int  size);
    73 
    74 /*********************************************************************************************
    75  * This function writes a formated string to the standard "stdout" stream.
    76  *********************************************************************************************
    77  * @ returns number of characters written if success / returns -1 if failure.
    78  ********************************************************************************************/
    79 int printf( const char * format, ... );
    80 
    81 /*********************************************************************************************
    82  * This function returns a positive integer fom the standard "stdin" stream.
    83  *********************************************************************************************
    84  * returns the integer value if success / returns -1 if failure.
    85  ********************************************************************************************/
    86 int getint();
    87 
    88 /*********************************************************************************************
    89  * This function writes one single character to the standard "stdout" stream.
    90  *********************************************************************************************
    91  * @ returns written character code if success / returns 0 (EOF) if failure.
    92  ********************************************************************************************/
    93 int putchar( int c );
    94 
    95 /*********************************************************************************************
    96  * This function returns one single character from the standard "stdin" stream.
    97  *********************************************************************************************
    98  * @ returns read character code if success / returns 0 (EOF) if failure.
    99  ********************************************************************************************/
    100 int getchar();
    101 
    102 /*********************************************************************************************
    103  * This function copies a formated string to a fixed size buffer.
    104  * it includes the NUL terminating character.
    105  * it cheks that the formated string fit in the buffer length.
    106  *********************************************************************************************
    107  * @ string    :  pointer on target buffer.
    108  * @ length    : max bumber of characters in target buffer.
    109  * @ format    : formated string.
    110  * @ returns number of characters written if success / returns -1 if failure.
    111  ********************************************************************************************/
    112 int snprintf( char         * string,
    113               unsigned int   length,
    114               const char   * format, ... );
    11548
    11649/*********************************************************************************************
     
    13063int rand();
    13164
    132 /*********************************************************************************************
    133  * This blocking function implements an user-level interactive debugger that can be
    134  * introduced in any user application to display various kernel distributed structures
    135  * related to the calling process. The supported commands are:
    136  * - p (cxy)     : display all processes descriptors in a given cluster.
    137  * - s (cxy,lid) : display all threads attached to a given core in a given cluster.
    138  * - v (cxy)     : display the calling process VMM in a given cluster.
    139  * - t (tid)     : display all owner process descriptors attached to a given TXT terminal.
    140  * - x           : force the calling process to exit.
    141  * - c           : continue calling process execution.
    142  *********************************************************************************************
    143  * @ return an integer value between 0 and RAND_MAX.
    144  ********************************************************************************************/
    145 void idbg();
     65/*****************************************************************************************
     66 * This function allocates <size> bytes of memory in user space and returns a pointer
     67 * on the allocated buffer. The physical memory is allocated from store located in
     68 * the calling core cluster.
     69 *****************************************************************************************
     70 * @ size    : number of requested bytes.
     71 * @ returns a pointer on the allocated buffer if success / returns NULL if failure
     72 ****************************************************************************************/
     73void * malloc( unsigned int size );
    14674
    14775
     76/*****************************************************************************************
     77 * This function releases the memory buffer identified by the <ptr> argument,
     78 * to the store located in the calling core cluster.
     79 * It displays an error message, but does nothing if the ptr is illegal.
     80 *****************************************************************************************
     81 * @ ptr   : pointer on the released buffer.
     82 ****************************************************************************************/
     83void free( void * ptr );
     84
     85/*****************************************************************************************
     86 * This function releases the memory buffer identified by the <ptr> argument,
     87 * to the store located in the calling core cluster, and allocates a new buffer
     88 * containing <size> bytes from this store.
     89 * The content of the old buffer is copied to the new buffer, up to <size> bytes.
     90 * It displays an error message, but does nothing if the ptr is illegal.
     91 *****************************************************************************************
     92 * @ ptr   : pointer on the released buffer.
     93 * @ size  : new buffer requested size (bytes).
     94 * @ return a pointer on allocated buffer if success / return NULL if failure
     95 ****************************************************************************************/
     96void * realloc( void        * ptr,
     97                unsigned int  size );
     98
     99
     100/*****************************************************************************************
     101 * This function allocates enough space for <count> objects that are <size> bytes
     102 * of memory each from the store located in the calling core cluster.
     103 * The allocated memory is filled with bytes of value zero.
     104 *****************************************************************************************
     105 * @ count   : number of requested objects.
     106 * @ size    : number of bytes per object.
     107 * @ returns a pointer on allocated buffer if success / returns NULL if failure
     108 ****************************************************************************************/
     109void * calloc( unsigned int count,
     110               unsigned int size );
    148111#endif  // _STDLIB_H_
  • trunk/libs/mini-libc/string.c

    r439 r444  
    2424#define  NULL  (void *)0
    2525
    26 ///////////////////////////
    27 inline int tolower( int c )
    28 {
    29    if (c >= 'A' && c <= 'Z') return (c | 0x20);
    30    else                      return c;
    31 }
    32 
    33 
    34 ///////////////////////////
    35 inline int toupper( int c )
    36 {
    37    if (c >= 'a' && c <= 'z') return (c & ~(0x20));
    38    else                      return c;
    39 }
     26#include <string.h>
    4027
    4128///////////////////////////////////////
     
    9279}
    9380
    94 //////////////////////////////////
    95 int strcasecmp( const char * str1,
    96                 const char * str2 )
    97 {
    98         char c1;
    99         char c2;
    10081
    101         do
    102     {
    103                 c1 = (char)toupper( (int)*++str1 );
    104                 c2 = (char)toupper( (int)*++str2 );
    105                 c2 = toupper(*++str2);
    106         }
    107     while(c1 && c1 == c2);
    108 
    109         return (c1 - c2);
    110 }
    11182
    11283///////////////////////////
     
    190161}
    191162
     163///////////////////////////////////////////////////////////////
     164void * memcpy(void *_dst, const void * _src, unsigned int size)
     165{
     166    unsigned int * dst = _dst;
     167    const unsigned int * src = _src;
     168    if (!((unsigned int) dst & 3) && !((unsigned int) src & 3) )
     169    {
     170        while (size > 3)
     171        {
     172            *dst++ = *src++;
     173            size -= 4;
     174        }
     175    }
    192176
     177    unsigned char *cdst = (unsigned char*)dst;
     178    unsigned char *csrc = (unsigned char*)src;
     179
     180    while (size--)
     181    {
     182        *cdst++ = *csrc++;
     183    }
     184    return _dst;
     185}
     186
     187//////////////////////////////////////////////////////////
     188inline void * memset(void * dst, int s, unsigned int size)
     189{
     190    char * a = (char *) dst;
     191    while (size--)
     192    {
     193        *a++ = (char)s;
     194    }
     195    return dst;
     196}
     197
     198
  • trunk/libs/mini-libc/string.h

    r439 r444  
    6969
    7070/********************************************************************************************
    71  * This function compares lexicographically the strings s1 and s2, ignoring case.
    72  ********************************************************************************************
    73  * @ s1   : pointer on string.
    74  * @ s2   : pointer on string.
    75  * @ return 0 if s1 == s2 / return 1 if s1 > s2 / return -1 if s1 < s2
    76  *******************************************************************************************/
    77 int strcasecmp ( const char * s1,
    78                  const char * s2 );
    79 
    80 /********************************************************************************************
    8171 * this function copies the <src> buffer to the <dst> buffer, including the terminating NUL.
    8272 ********************************************************************************************
     
    128118                 int          c );
    129119
    130 /********************************************************************************************
    131  * This function returns a lower case ASCII code if input is in [A...Z] range.
    132  ********************************************************************************************
    133  * @ c     : the 8 LSB bits define the character to be forced to lower case.
    134  * @ return lower case ASCII code.
    135  *******************************************************************************************/
    136 inline int tolower( int  c );
    137120
    138 /********************************************************************************************
    139  * This function returns an upper case ASCII code if input is in [a...z] range.
    140  ********************************************************************************************
    141  * @ c     : the 8 LSB bits define the character to be forced to upper case.
    142  * @ return upper case ASCII code.
    143  *******************************************************************************************/
    144 inline int toupper( int  c );
     121/*********************************************************************************************
     122 * This function copies the content of a <src> byte array to a <dst> byte array.
     123 * Behaviour is undefined if <src> and <dst> arrays overlap.
     124 *********************************************************************************************
     125 * @ dst     : pointer on destination array.
     126 * @ dst     : pointer on source array.
     127 * @ size    : number of bytes to move.
     128 * @ return first argument.
     129 ********************************************************************************************/
     130void * memcpy( void         * dst,
     131               const void   * src,
     132               unsigned int   size );
     133
     134/*********************************************************************************************
     135 * This function fill a byte array with a byte value.
     136 *********************************************************************************************
     137 * @ dst     : pointer on the byte array.
     138 * @ s       : byte value (will be casted to unsigned char).
     139 * @ size    : number of bytes to be set.
     140 * @ return first argument.
     141 ********************************************************************************************/
     142void * memset( void        * dst,
     143               int           s,
     144               unsigned int  size);
    145145
    146146#endif  /* _STRING_H_ */
  • trunk/libs/mini-libpthread/Makefile

    r440 r444  
    99
    1010SRCS = pthread.c
    11 OBJS = $(addprefix build/, $(SRCS:.c=.o)) \
    12        $(HAL_ARCH)/build/core/hal_user.o
    13 OBJS_LIBC = ../mini-libc/build/malloc.o ../mini-libc/build/stdlib.o ../mini-libc/build/stdio.o
     11OBJS = $(addprefix build/, $(SRCS:.c=.o))
     12#       $(HAL_ARCH)/build/core/hal_user.o
    1413
    15 INCLUDES = -I. -I$(KERNEL)/syscalls -I$(HAL)/generic -I../mini-libc
     14INCLUDES = -I. -I$(HAL)/generic -I$(LIBC_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE)
    1615
    17 libs : build/lib/libpthread.a
     16libs : build/lib/libpthread.a headers
    1817
    1918build :
     
    3231        $(DU) -D $@ > $@.txt
    3332
     33headers: build
     34        cp $(SRCS:.c=.h) build/include/.
     35
     36
    3437build/lib/libpthread.a: build $(OBJS)
    35         $(AR) rc $@ $(OBJS) $(OBJS_LIBC)
     38        $(AR) rc $@ $(OBJS) #$(OBJS_LIBC)
    3639        $(RANLIB) $@
    37         cp $(SRCS:.c=.h) $(HAL)/generic/hal_user.h $(KERNEL)/syscalls/shared_syscalls.h build/include/.
    3840
    39 .PHONY = build clean
     41.PHONY = build clean headers
    4042
    4143
    4244clean:
    43         rm -f build/*.o build/*.txt build/include/* build/lib/*
     45        rm -rf build/
  • trunk/libs/mini-libpthread/pthread.c

    r440 r444  
    2222 */
    2323
    24 #include <shared_syscalls.h>
    2524#include <hal_user.h>
    2625#include <stdio.h>
    2726#include <stdlib.h>
    28 #include <malloc.h>
    2927#include <pthread.h>
     28#include <assert.h>
     29#include <almos-mkh.h>
     30#include <syscalls_numbers.h>
    3031
    3132#define PTHREAD_MUTEX_DEBUG     0
  • trunk/libs/mini-libpthread/pthread.h

    r439 r444  
    2525#define _PTHREAD_H_
    2626
    27 #include <shared_syscalls.h>
     27#include <almos-mkh/pthread.h>
     28
    2829
    2930//////////////////////////////////////////////////////////////////////////////////////////////
     
    7778int pthread_exit( void * exit_value );
    7879
     80
     81
     82// TODO n'existe pas dans pthread
    7983/*********************************************************************************************
    8084 * This function calls the scheduler for the core running the calling thread.
     
    247251
    248252
    249 #endif  // _STDIO_H_
     253#endif  // _PTHREAD_H_
  • trunk/params-soft.mk

    r440 r444  
    11
    22#put your absolute path to almos-mkh dir here
    3 ALMOS-MKH_DIR = /Users/alain/soc/almos-mkh
     3ALMOSMKH_DIR = /Users/alain/soc/almos-mkh
    44
    55LIBC_NAME = mini-libc
     
    1111LIBPTHREAD_NAME = mini-libpthread
    1212
    13 ifeq ($(ALMOS-MKH_DIR),)
    14 $(error Please define ALMOS-MKH_DIR parameter in params-soft.mk!)
     13ifeq ($(ALMOSMKH_DIR),)
     14$(error Please define ALMOSMKH_DIR parameter in params-soft.mk!)
    1515endif
    1616
    1717
    1818ifeq ($(LIBC_NAME), mini-libc)
    19   LIBC_PATH = $(ALMOS-MKH_DIR)/libs/mini-libc/
     19  LIBC_PATH = $(ALMOSMKH_DIR)/libs/mini-libc/
     20  LIBC = $(LIBC_PATH)/build/lib/
     21  LIBC_INCLUDE = $(LIBC_PATH)/build/include/
    2022endif
    2123ifeq ($(LIBC_NAME), newlib)
    22   LIBC_PATH = $(ALMOS-MKH_DIR)/libs/newlib/
     24  ifeq ($(ARCH_NAME), tsar_mips32)
     25    ARCH_NEWLIB=mipsel
     26  endif
     27  #TODO for x86
     28  LIBC_PATH = $(ALMOSMKH_DIR)/libs/newlib/
     29  LIBC = $(LIBC_PATH)/build/$(ARCH_NEWLIB)-almosmkh/lib/
     30  LIBC_INCLUDE = $(LIBC_PATH)/build/$(ARCH_NEWLIB)-almosmkh/include/
    2331endif
    2432
    2533ifeq ($(LIBPTHREAD_NAME), mini-libpthread)
    26   LIBPTHREAD_PATH = $(ALMOS-MKH_DIR)/libs/mini-libpthread/
     34  LIBPTHREAD_PATH = $(ALMOSMKH_DIR)/libs/mini-libpthread/
    2735endif
    2836
     37LIBALMOSMKH_PATH = $(ALMOSMKH_DIR)/libs/libalmos-mkh
    2938#Define path to .a and headers files for libc and libpthread
    30 LIBC = $(LIBC_PATH)/build/lib/
    31 LIBC_INCLUDE = $(LIBC_PATH)/build/include/
    3239LIBPTHREAD = $(LIBPTHREAD_PATH)/build/lib/
    3340LIBPTHREAD_INCLUDE = $(LIBPTHREAD_PATH)/build/include/
     41LIBALMOSMKH = $(LIBALMOSMKH_PATH)/build/lib/
     42LIBALMOSMKH_INCLUDE = $(LIBALMOSMKH_PATH)/build/include/
    3443
    3544
    36 HAL  = $(ALMOS-MKH_DIR)/hal
    37 KERNEL = $(ALMOS-MKH_DIR)/kernel
     45HAL  = $(ALMOSMKH_DIR)/hal
     46KERNEL = $(ALMOSMKH_DIR)/kernel
     47SHARED_INCLUDE = $(KERNEL)/syscalls/shared_include/
    3848
    3949
  • trunk/user/idbg/Makefile

    r442 r444  
    1111OBJS = build/idbg.o
    1212
    13 INCLUDES = -I. -I$(LIBC_INCLUDE)
     13INCLUDES = -I. -I$(LIBC_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE) -I$(LIBPTHREAD_INCLUDE)
    1414
    1515compile: dirs build/idbg.elf
    1616
    1717build/idbg.elf : $(OBJS) idbg.ld
    18         $(LD) -o $@ -T idbg.ld $(OBJS) -nostdlib -L$(LIBC) -lc
     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
    1919        $(DU) -D $@ > $@.txt
    2020
  • trunk/user/idbg/idbg.c

    r442 r444  
    1111#include <stdlib.h>
    1212#include <stdio.h>
    13 #include <shared_syscalls.h>
     13#include <almos-mkh.h>
    1414
    1515///////////
  • trunk/user/init/Makefile

    r440 r444  
    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) \
     17           -I$(LIBALMOSMKH_INCLUDE) \
     18           -I$(SHARED_INCLUDE)
    1719
    1820compile : dirs build/init.elf
    1921build/init.elf : $(OBJS) init.ld
    20         $(LD) -o $@ -T init.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -lc -lpthread
     22        $(LD) -o $@ -T init.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -lc -lpthread -lalmos-mkh -lpthread -lc
    2123        $(DU) -D $@ > $@.txt
    2224
  • trunk/user/init/init.c

    r442 r444  
    1313
    1414#include <hard_config.h>
    15 
     15#include <unistd.h>
    1616#include <stdlib.h>
    1717#include <stdio.h>
    1818#include <pthread.h>
     19#include <almos-mkh.h>
     20#include <assert.h>
     21#include <sys/wait.h>
    1922
    2023#define DEBUG_PROCESS_INIT    0
     
    5457        {
    5558            // CHILD[i] process exec process KSH[i]
    56             ret_exec = exec( "/bin/user/ksh.elf" , NULL , NULL );
     59            ret_exec = execve( "/bin/user/ksh.elf" , NULL , NULL );
    5760
    5861            if ( ret_exec )   // error in exec             
     
    139142            {
    140143                // CHILD process exec process KSH
    141                 ret_exec = exec( "/bin/user/ksh.elf" , NULL , NULL );
     144                ret_exec = execve( "/bin/user/ksh.elf" , NULL , NULL );
    142145
    143146                if ( ret_exec )   // error in exec             
  • trunk/user/ksh/Makefile

    r440 r444  
    1010OBJS = build/ksh.o
    1111
    12 INCLUDES = -I. -I$(LIBC_INCLUDE) -I$(LIBPTHREAD_INCLUDE)
     12INCLUDES = -I. -I$(LIBC_INCLUDE) -I$(LIBPTHREAD_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE)
    1313
    1414compile: dirs build/ksh.elf
    1515build/ksh.elf : $(OBJS) ksh.ld
    16         $(LD) -o $@ -T ksh.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -lc -lpthread
     16        $(LD) -o $@ -T ksh.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -lpthread -lc -lalmos-mkh -lc -lpthread -lc
    1717        $(DU) -D $@ > $@.txt
    1818
  • trunk/user/ksh/ksh.c

    r442 r444  
    1010#include <stdlib.h>
    1111#include <string.h>
    12 #include <shared_syscalls.h>
     12#include <sys/wait.h>
     13#include <signal.h>
     14#include <unistd.h>
     15#include <almos-mkh.h>
    1316
    1417#define CMD_MAX_SIZE   (256)    // max number of characters in one command
     
    425428    {
    426429        // CHILD process exec NEW process
    427         ret_exec = exec( pathname , NULL , NULL );
     430        ret_exec = execve( pathname , NULL , NULL );
    428431
    429432        // this is only executed in case of exec failure
  • trunk/user/pgcd/Makefile

    r440 r444  
    1111OBJS = build/pgcd.o
    1212
    13 INCLUDES = -I. -I$(LIBC_INCLUDE)
     13INCLUDES = -I. -I$(LIBC_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE) -I$(LIBPTHREAD_INCLUDE)
    1414
    1515compile: dirs build/pgcd.elf
    1616
    1717build/pgcd.elf : $(OBJS) pgcd.ld
    18         $(LD) -o $@ -T pgcd.ld $(OBJS) -nostdlib -L$(LIBC) -lc
     18        $(LD) -o $@ -T pgcd.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBALMOSMKH) -L$(LIBPTHREAD) -lalmos-mkh -lc -lalmos-mkh -lpthread -lc
    1919        $(DU) -D $@ > $@.txt
    2020
    2121build/pgcd.o : pgcd.c
    22         $(CC) $(INCLUDES) -L$(LIBC) $(CFLAGS) -c -o  $@ $<
     22        $(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
     23        $(DU) -D $@ > $@.txt
    2324
    2425dirs:
  • trunk/user/pgcd/pgcd.c

    r442 r444  
    1010#include <stdlib.h>
    1111#include <stdio.h>
    12 
     12#include <almos-mkh.h>
    1313
    1414///////////
  • trunk/user/sort/Makefile

    r440 r444  
    1111OBJS = build/sort.o
    1212
    13 INCLUDES = -I. -I$(LIBC_INCLUDE) -I$(LIBPTHREAD_INCLUDE)
     13INCLUDES = -I. -I$(LIBC_INCLUDE) -I$(LIBPTHREAD_INCLUDE) -I$(LIBALMOSMKH_INCLUDE) -I$(SHARED_INCLUDE)
    1414
    1515compile: dirs build/sort.elf
    1616
    1717build/sort.elf : $(OBJS) sort.ld
    18         $(LD) -o $@ -T sort.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -lc -lpthread
     18        $(LD) -o $@ -T sort.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -L$(LIBALMOSMKH) -lpthread -lalmos-mkh -lc
    1919        $(DU) -D $@ > $@.txt
    2020
  • trunk/user/sort/sort.c

    r442 r444  
    2424#include <stdio.h>
    2525#include <stdlib.h>
    26 #include <malloc.h>
    2726#include <pthread.h>
     27#include <almos-mkh.h>
    2828
    2929#define ARRAY_LENGTH        0x400    // 1024 values
Note: See TracChangeset for help on using the changeset viewer.