Changeset 228 for soft/giet_vm/libs


Ignore:
Timestamp:
Feb 12, 2013, 6:33:31 PM (11 years ago)
Author:
meunier
Message:

Added support for memspaces and const.
Added an interrupt masking to the "giet_context_switch" syscall
Corrected two bugs in boot/boot_init.c (one minor and one regarding barriers initialization)
Reformatted the code in all files.

Location:
soft/giet_vm/libs
Files:
1 added
22 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/libs/barrier.c

    r165 r228  
    1515
    1616///////////////////////////////////////////////////////////////////////////////////
    17 //      barrier_init()
     17//     barrier_init()
    1818// This function makes a cooperative initialisation of the barrier:
    1919// several tasks try to initialize the barrier, but the initialisation
    2020// is done by only one task, using LL/SC instructions.
    2121///////////////////////////////////////////////////////////////////////////////////
    22 void barrier_init( giet_barrier_t*      barrier,
    23                    unsigned int         value )
    24 {
    25     unsigned int* pinit  = (unsigned int*)&barrier->init;
    26     unsigned int* pcount = (unsigned int*)&barrier->count;
     22void barrier_init( giet_barrier_t * barrier, unsigned int value) {
     23    unsigned int * pinit  = (unsigned int *) &barrier->init;
     24    unsigned int * pcount = (unsigned int *) &barrier->count;
    2725
    2826    // parallel initialisation using atomic instructions LL/SC
     
    3028    // no output
    3129    asm volatile ("_barrier_init_test:                  \n"
    32                   "ll   $2,     0(%0)                   \n" /* read initial value */
    33                   "bnez $2,     _barrier_init_done      \n"
    34                   "move $3,     %2                      \n"
    35                   "sc   $3,     0(%0)                   \n" /* write initial value */
    36                   "beqz $3,     _barrier_init_test      \n"
    37                   "move $3,     %2                      \n"
    38                   "sw   $3,     0(%1)                   \n" /* write count */
    39                   "_barrier_init_done:                  \n"
    40                   :: "r"(pinit), "r"(pcount), "r"(value)
    41                   : "$2", "$3");
     30            "ll   $2,     0(%0)                   \n" /* read initial value */
     31            "bnez $2,     _barrier_init_done      \n"
     32            "move $3,     %2                      \n"
     33            "sc   $3,     0(%0)                   \n" /* write initial value */
     34            "beqz $3,     _barrier_init_test      \n"
     35            "move $3,     %2                      \n"
     36            "sw   $3,     0(%1)                   \n" /* write count */
     37            "_barrier_init_done:                  \n"
     38            :
     39            : "r"(pinit), "r"(pcount), "r"(value)
     40            : "$2", "$3");
    4241}
     42
     43
    4344///////////////////////////////////////////////////////////////////////////////////
    44 //      barrier_wait()
     45//    barrier_wait()
    4546// This blocking function uses LL/SC to decrement the barrier's counter.
    4647// Then, it uses a busy_waiting mechanism if it is not the last.
    4748// (because the GIET does not support dynamic task scheduling/descheduling)
    4849///////////////////////////////////////////////////////////////////////////////////
    49 void barrier_wait( giet_barrier_t* barrier )
    50 {
    51     unsigned int* pcount  = (unsigned int*)&barrier->count;
     50void barrier_wait(giet_barrier_t * barrier) {
     51    unsigned int * pcount  = (unsigned int *) &barrier->count;
    5252    unsigned int maxcount = barrier->init;
    5353    unsigned int count;
     
    5757    // - output : counter value
    5858    asm volatile ("_barrier_decrement:          \n"
    59                   "ll   %0, 0(%1)               \n"
    60                   "addi $3, %0,     -1          \n"
    61                   "sc   $3, 0(%1)               \n"
    62                   "beqz $3, _barrier_decrement  \n"
    63                   : "=&r"(count)
    64                   : "r"(pcount)
    65                   : "$2", "$3");
     59            "ll   %0, 0(%1)               \n"
     60            "addi $3, %0,     -1          \n"
     61            "sc   $3, 0(%1)               \n"
     62            "beqz $3, _barrier_decrement  \n"
     63            : "=&r"(count)
     64            : "r"(pcount)
     65            : "$2", "$3");
    6666
    6767    // the last task re-initializes the barrier counter to the max value,
    6868    // waking up all other waiting tasks
    6969
    70     if (count == 1)             // last task
    71     {
     70    if (count == 1) {
     71        // last task
    7272        *pcount = maxcount;
    7373    }
    74     else                        // other tasks busy-wait
    75     {
     74    else {
     75        // other tasks busy-wait
    7676        while (*pcount != maxcount) asm volatile ("nop");
    7777    }
    7878}
    7979
     80// Local Variables:
     81// tab-width: 4
     82// c-basic-offset: 4
     83// c-file-offsets:((innamespace . 0)(inline-open . 0))
     84// indent-tabs-mode: nil
     85// End:
     86// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     87
  • soft/giet_vm/libs/barrier.h

    r165 r228  
    1414
    1515typedef struct giet_barrier_s {
    16     char                name[32];       // barrier name
    17     unsigned int        init;   // total number of participants
    18     unsigned int        count;  // number of not yet arrived tasks
     16    char name[32];      // barrier name
     17    unsigned int init;  // total number of participants
     18    unsigned int count; // number of not yet arrived tasks
    1919} giet_barrier_t;
    2020
     
    2323//////////////////////////////////////////////////////////////////////////////
    2424
    25 void barrier_init( giet_barrier_t*      barrier,
    26                    unsigned int         value );
    27 
    28 void barrier_wait( giet_barrier_t*      barrier );
     25void barrier_init(giet_barrier_t * barrier, unsigned int value);
     26void barrier_wait(giet_barrier_t * barrier);
    2927
    3028#endif
    3129
     30// Local Variables:
     31// tab-width: 4
     32// c-basic-offset: 4
     33// c-file-offsets:((innamespace . 0)(inline-open . 0))
     34// indent-tabs-mode: nil
     35// End:
     36// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     37
  • soft/giet_vm/libs/common.h

    r178 r228  
    1616 */
    1717//////////////////////////////////////////////////////////////////////////
    18 static inline void *memcpy(void *_dst, const void *_src, unsigned int size)
    19 {
    20     unsigned int *dst = _dst;
    21     const unsigned int *src = _src;
     18static inline void * memcpy(void * _dst, const void * _src, unsigned int size) {
     19    unsigned int * dst = _dst;
     20    const unsigned int * src = _src;
    2221
    2322    /* if source and destination buffer are word-aligned,
    2423     * then copy word-by-word */
    25     if (!((unsigned int)dst & 3) && !((unsigned int)src & 3))
     24    if (!((unsigned int)dst & 3) && !((unsigned int)src & 3)) {
    2625        while (size > 3) {
    2726            *dst++ = *src++;
    2827            size -= 4;
    2928        }
     29    }
    3030
    31     unsigned char *cdst = (unsigned char*)dst;
    32     unsigned char *csrc = (unsigned char*)src;
     31    unsigned char * cdst = (unsigned char *) dst;
     32    unsigned char * csrc = (unsigned char *) src;
    3333
    3434    /* byte-by-byte copy */
     
    3939}
    4040
     41
    4142//////////////////////////////////////////////////////////
    42 static inline void * memset(void *dst, int s, unsigned int count)
    43 {
    44         char *a = (char *) dst;
    45         while (count--)
    46                 *a++ = (char)s;
    47         return dst;
     43static inline void * memset(void * dst, int s, unsigned int count) {
     44    char * a = (char *) dst;
     45    while (count--) {
     46        *a++ = (char) s;
     47    }
     48    return dst;
    4849}
    4950
     51
    5052/**
    51    the same as the C assert.
    52    Taken from Mutekh(SRL API)
    53  */
    54 #define assert(expr)                                                                                                \
    55     do {                                                                                                                                \
    56         if ( ! (expr) ) {                                                                                               \
     53  the same as the C assert.
     54  Taken from Mutekh(SRL API)
     55  */
     56#define assert(expr)                                                    \
     57    do {                                                                \
     58        if ( ! (expr) ) {                                                \
    5759            giet_tty_printf("assertion (%s) failed on %s:%d !\n",  \
    58                                                    #expr, __FILE__, __LINE__ );                                 \
    59             __abort();                                                                                          \
    60         }                                                                                                                               \
     60#expr, __FILE__, __LINE__ );                    \
     61            __abort();                                                \
     62        }                                                                \
    6163    } while(0)
    6264
    6365/**
    64    @this aborts the current execution.
    65    Taken from Mutekh(SRL API)
    66  */
    67 static inline void __abort()
    68 {
    69         asm volatile ("break 0");
    70         while(1);
     66  @this aborts the current execution.
     67  Taken from Mutekh(SRL API)
     68  */
     69static inline void __abort() {
     70    asm volatile ("break 0");
     71    while (1);
    7172}
    7273
    7374#endif /* _COMMON_H_ */
     75
     76
     77// Local Variables:
     78// tab-width: 4
     79// c-basic-offset: 4
     80// c-file-offsets:((innamespace . 0)(inline-open . 0))
     81// indent-tabs-mode: nil
     82// End:
     83// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     84
  • soft/giet_vm/libs/libsrl/srl_args.h

    r215 r228  
    44
    55
    6 #define SRL_GET_MWMR(port)      (srl_mwmr_t) APP_GET_ARG(port, VOBJ_TYPE_MWMR)
    7 #define SRL_GET_BARRIER(port)   APP_GET_ARG(port, VOBJ_TYPE_BARRIER)
    8 #define SRL_GET_LOCK(port)      APP_GET_ARG(port, VOBJ_TYPE_LOCK)
    9 //#define SRL_GET_MEMSPACE(port)  APP_GET_ARG(port, VOBJ_TYPE_BUFFER) TODO
    10 #define SRL_GET_MEMSPACE        #error "SRL_GET_MEMSPACE is not implemented"//
     6#define SRL_GET_MWMR(port)      (srl_mwmr_t)     APP_GET_ARG(port, VOBJ_TYPE_MWMR)
     7#define SRL_GET_BARRIER(port)   (srl_barrier_t)  APP_GET_ARG(port, VOBJ_TYPE_BARRIER)
     8#define SRL_GET_LOCK(port)                       APP_GET_ARG(port, VOBJ_TYPE_LOCK)
     9#define SRL_GET_CONST(port)                      APP_GET_ARG(port, VOBJ_TYPE_CONST)
     10#define SRL_GET_MEMSPACE(port)  (srl_memspace_t) APP_GET_ARG(port, VOBJ_TYPE_MEMSPACE)
    1111
    1212
     
    1414({                                                                                                 \
    1515    unsigned int  vbase;                                                                           \
    16     if( giet_vobj_get_vbase( APP_NAME , alias_##task_name.port, type, &vbase ) )                   \
     16    if (giet_vobj_get_vbase(APP_NAME , alias_##task_name.port, type, &vbase))                      \
    1717    {                                                                                              \
    18         srl_log_printf( NONE, "\n[ERROR] in "#task_name" task :\n");                               \
    19         srl_log_printf( NONE, "          undefined port <"#port"> for channel(%s): %d\n",          \
    20                                                                 alias_##task_name.port,vbase);     \
    21         srl_log_printf( TRACE, "*** &"#port" = %x\n\n", vbase );                                   \
     18        srl_log_printf(NONE, "\n[ERROR] in "#task_name" task :\n");                                \
     19        srl_log_printf(NONE, "          undefined port <"#port"> for channel \"%s\": %x\n",        \
     20                                                                alias_##task_name.port, vbase);    \
     21        srl_log_printf(TRACE, "*** &"#port" = %x\n\n", vbase);                                     \
    2222        srl_exit();                                                                                \
    23     }else                                                                                          \
    24         srl_log_printf( TRACE, "%s:%d: arg of %s for %s,from %s; &"#port" = %x\n\n",               \
    25                             __FILE__, __LINE__, APP_NAME, #task_name,#port, vbase );               \
    26     vbase;\
     23    }                                                                                              \
     24    else                                                                                           \
     25        srl_log_printf(TRACE, "%s:%d: arg of %s for %s, from %s; &"#port" = %x\n\n",               \
     26                            __FILE__, __LINE__, APP_NAME, #task_name, #port, vbase);               \
     27    vbase;                                                                                         \
    2728})
    2829
  • soft/giet_vm/libs/libsrl/srl_barrier.h

    r178 r228  
    2323
    2424
    25 typedef giet_barrier_t *srl_barrier_t;
     25typedef giet_barrier_t * srl_barrier_t;
    2626
    2727#define srl_barrier_wait(bar) barrier_wait(bar)
    2828
    2929#endif
     30
     31
     32// Local Variables:
     33// tab-width: 4
     34// c-basic-offset: 4
     35// c-file-offsets:((innamespace . 0)(inline-open . 0))
     36// indent-tabs-mode: nil
     37// End:
     38// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     39
  • soft/giet_vm/libs/libsrl/srl_endianness.h

    r160 r228  
    55
    66/** @this reads a big endian 16 bits value */
    7 #  define endian_le16(x)        (x)
     7#  define endian_le16(x)    (x)
    88/** @this reads a big endian 32 bits value */
    9 #  define endian_le32(x)        (x)
     9#  define endian_le32(x)    (x)
    1010/** @this reads a big endian 64 bits value */
    11 //#  define endian_le64(x)      (x)
     11//#  define endian_le64(x)    (x)
    1212/** @this reads a little endian 16 bits value */
    13 #  define endian_be16(x)        endian_swap16(x)
     13#  define endian_be16(x)    endian_swap16(x)
    1414/** @this reads a little endian 32 bits value */
    15 #  define endian_be32(x)        endian_swap32(x)
     15#  define endian_be32(x)    endian_swap32(x)
    1616/** @this reads a little endian 64 bits value */
    17 //#  define endian_be64(x)      endian_swap64(x)
     17//#  define endian_be64(x)    endian_swap64(x)
    1818
    1919/** @internal */
    20 static inline uint16_t endian_swap16(uint16_t x)
    21 {
    22   return (x >> 8) | (x << 8);
     20static inline uint16_t endian_swap16(uint16_t x) {
     21    return (x >> 8) | (x << 8);
    2322}
    2423
     24
    2525/** @internal */
    26 static inline uint32_t endian_swap32(uint32_t x)
    27 {
    28   return (((x >> 24) & 0x000000ff) |
    29           ((x >> 8 ) & 0x0000ff00) |
    30           ((x << 8 ) & 0x00ff0000) |
    31           ((x << 24) & 0xff000000));
     26static inline uint32_t endian_swap32(uint32_t x) {
     27    return (((x >> 24) & 0x000000ff) |
     28            ((x >> 8 ) & 0x0000ff00) |
     29            ((x << 8 ) & 0x00ff0000) |
     30            ((x << 24) & 0xff000000));
    3231}
    3332
     33
    3434/** @internal *//*
    35 static inline uint64_t __endian_swap64(uint64_t x)
    36 {
    37   return (((uint64_t)endian_swap32(x      ) << 32) |
    38           ((uint64_t)endian_swap32(x >> 32)      ));
    39 }*/
     35                   static inline uint64_t __endian_swap64(uint64_t x)
     36                   {
     37                   return (((uint64_t)endian_swap32(x      ) << 32) |
     38                   ((uint64_t)endian_swap32(x >> 32)      ));
     39                   }*/
    4040
    41 static inline uint32_t srl_uint32_le_to_machine(uint32_t x)
    42 {
    43         return endian_le32(x);
     41static inline uint32_t srl_uint32_le_to_machine(uint32_t x) {
     42    return endian_le32(x);
    4443}
    4544
    46 static inline uint32_t srl_uint32_machine_to_le(uint32_t x)
    47 {
    48         return endian_le32(x);
     45
     46static inline uint32_t srl_uint32_machine_to_le(uint32_t x) {
     47    return endian_le32(x);
    4948}
    5049
    51 static inline uint32_t srl_uint32_be_to_machine(uint32_t x)
    52 {
    53         return endian_be32(x);
     50
     51static inline uint32_t srl_uint32_be_to_machine(uint32_t x) {
     52    return endian_be32(x);
    5453}
    5554
    56 static inline uint32_t srl_uint32_machine_to_be(uint32_t x)
    57 {
    58         return endian_be32(x);
     55
     56static inline uint32_t srl_uint32_machine_to_be(uint32_t x) {
     57    return endian_be32(x);
    5958}
    6059
    61 static inline uint16_t srl_uint16_le_to_machine(uint16_t x)
    62 {
    63         return endian_le16(x);
     60
     61static inline uint16_t srl_uint16_le_to_machine(uint16_t x) {
     62    return endian_le16(x);
    6463}
    6564
    66 static inline uint16_t srl_uint16_machine_to_le(uint16_t x)
    67 {
    68         return endian_le16(x);
     65
     66static inline uint16_t srl_uint16_machine_to_le(uint16_t x) {
     67    return endian_le16(x);
    6968}
    7069
    71 static inline uint16_t srl_uint16_be_to_machine(uint16_t x)
    72 {
    73         return endian_be16(x);
     70
     71static inline uint16_t srl_uint16_be_to_machine(uint16_t x) {
     72    return endian_be16(x);
    7473}
    7574
    76 static inline uint16_t srl_uint16_machine_to_be(uint16_t x)
    77 {
    78         return endian_be16(x);
     75
     76static inline uint16_t srl_uint16_machine_to_be(uint16_t x) {
     77    return endian_be16(x);
    7978}
    8079
    8180
    8281#endif
     82
     83
     84// Local Variables:
     85// tab-width: 4
     86// c-basic-offset: 4
     87// c-file-offsets:((innamespace . 0)(inline-open . 0))
     88// indent-tabs-mode: nil
     89// End:
     90// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     91
  • soft/giet_vm/libs/libsrl/srl_hw_helpers.h

    r178 r228  
    1212
    1313/**
    14    Standard API call, expands to nothing for this implementation.
    15  */
     14  Standard API call, expands to nothing for this implementation.
     15  */
    1616#define srl_busy_cycles(n) do{}while(0)
    1717
    1818//void useless(void *pointless,...){}
    1919/**
    20    @this flushes the cache line containing the address.
    21  */
     20  @this flushes the cache line containing the address.
     21  */
    2222//TODO
    2323#define srl_dcache_flush_addr 0
    2424
    2525/*
    26 static inline cpu_dcache_invld(void *ptr){
    27          asm volatile (                                                         
    28         " cache %0, %1"                                                 
    29         : : "i" (0x11) , "R" (*(uint8_t*)(ptr))
    30         : "memory"                                                             
    31         );                                                     
    32 }
    33 */
     26   static inline cpu_dcache_invld(void *ptr){
     27   asm volatile (                               
     28   " cache %0, %1"                           
     29   : : "i" (0x11) , "R" (*(uint8_t*)(ptr))   
     30   : "memory"                               
     31   );                           
     32   }
     33   */
    3434
    3535/**
    36    @this flushes a memory zone from cache.
    37  */
     36  @this flushes a memory zone from cache.
     37  */
    3838//TODO
    3939//void dcache_flush(const void * addr, size_t size)
     
    4141
    4242/**
    43    @this waits for at least the given time (in cycles). The actual
    44    time spent in this call is not predictable.
     43  @this waits for at least the given time (in cycles). The actual
     44  time spent in this call is not predictable.
    4545
    46    @param time Number of cycles to wait for
    47  */
    48 void srl_sleep_cycles( unsigned int time );
     46  @param time Number of cycles to wait for
     47  */
     48void srl_sleep_cycles(unsigned int time);
    4949
    5050/**
    51    @this returns the absolute timestamp counter from the
    52    initialization of the platform.
     51  @this returns the absolute timestamp counter from the
     52  initialization of the platform.
    5353
    54    @return Cycles from the initialization of the system
    55  */
    56 static inline unsigned int srl_cycle_count()
    57 {
    58         return giet_proctime();
     54  @return Cycles from the initialization of the system
     55  */
     56static inline unsigned int srl_cycle_count() {
     57    return giet_proctime();
    5958}
    6059
     60
    6161/**
    62    @this aborts the current execution. On most systems, @this will
    63    simply hang.
    64  */
    65 static inline void srl_abort()
    66 {
    67         asm volatile ("break 0");
    68         while(1);
     62  @this aborts the current execution. On most systems, @this will
     63  simply hang.
     64  */
     65static inline void srl_abort() {
     66    asm volatile ("break 0");
     67    while (1);
    6968}
     69
    7070
    7171/**
    7272 *
    7373 */
    74 static inline void srl_exit()
    75 {
     74static inline void srl_exit() {
    7675    giet_exit();
    7776}
    7877
    7978#endif
     79
     80// Local Variables:
     81// tab-width: 4
     82// c-basic-offset: 4
     83// c-file-offsets:((innamespace . 0)(inline-open . 0))
     84// indent-tabs-mode: nil
     85// End:
     86// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     87
  • soft/giet_vm/libs/libsrl/srl_lock.h

    r178 r228  
    2323#include "spin_lock.h"
    2424
    25 typedef giet_lock_t* srl_lock_t;
     25typedef giet_lock_t * srl_lock_t;
    2626
    2727/**
     
    4949
    5050#endif
     51
     52
     53// Local Variables:
     54// tab-width: 4
     55// c-basic-offset: 4
     56// c-file-offsets:((innamespace . 0)(inline-open . 0))
     57// indent-tabs-mode: nil
     58// End:
     59// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     60
  • soft/giet_vm/libs/libsrl/srl_memspace.h

    r178 r228  
    11#ifndef SRL_MEMSPACE_H
    22#define SRL_MEMSPACE_H
     3
     4#include "srl_public_types.h"
     5
     6#include <memspace.h>
    37
    48/**
     
    1216   The memspace abstract type.
    1317 */
    14 typedef void* srl_memspace_t;
     18
     19
     20typedef giet_memspace_t * srl_memspace_t;
    1521
    1622/**
     
    2127 */
    2228#define SRL_MEMSPACE_SIZE(memsp) ((memsp)->size)
     29#define SRL_MEMSPACE_ADDR(memsp) ((memsp)->buffer)
     30
    2331
    2432#endif
     33
     34// Local Variables:
     35// tab-width: 4
     36// c-basic-offset: 4
     37// c-file-offsets:((innamespace . 0)(inline-open . 0))
     38// indent-tabs-mode: nil
     39// End:
     40// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     41
  • soft/giet_vm/libs/libsrl/srl_mwmr.h

    r213 r228  
    44#include "mwmr_channel.h"
    55
    6 typedef  mwmr_channel_t* srl_mwmr_t;
     6typedef  mwmr_channel_t * srl_mwmr_t;
    77
    8 #define srl_mwmr_write(a, b, c) mwmr_write(a, (unsigned int*) b, (unsigned int)c)
    9 #define srl_mwmr_read(a, b, c) mwmr_read(a, (unsigned int*) b, (unsigned int)c) 
     8#define srl_mwmr_write(a, b, c) mwmr_write(a, (unsigned int *) b, (unsigned int) c)
     9#define srl_mwmr_read(a, b, c) mwmr_read(a, (unsigned int *) b, (unsigned int) c)
    1010
    1111
    1212#endif //fin de SRL_MWMR_H_
     13
     14// Local Variables:
     15// tab-width: 4
     16// c-basic-offset: 4
     17// c-file-offsets:((innamespace . 0)(inline-open . 0))
     18// indent-tabs-mode: nil
     19// End:
     20// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     21
  • soft/giet_vm/libs/libsrl/srl_private_types.c

    r160 r228  
     1
    12#include "srl_private_types.h"
    23
     
    67// GCC requires this function. Taken from MutekH.
    78////////////////////////////////////////////////////////////////////////////////////////
    8 void *memcpy(void *_dst, const void *_src, unsigned int size)
    9 {
    10     unsigned int *dst = _dst;
    11     const unsigned int *src = _src;
    12     if ( ! ((unsigned int)dst & 3) && ! ((unsigned int)src & 3) )
     9void * memcpy(void *_dst, const void * _src, unsigned int size) {
     10    unsigned int * dst = _dst;
     11    const unsigned int * src = _src;
     12    if (!((unsigned int) dst & 3) && !((unsigned int) src & 3) )
    1313        while (size > 3) {
    1414            *dst++ = *src++;
     
    2525}
    2626
     27
    2728////////////////////////////////////////////////////////////////////////////////////////
    2829//  mempcy()
    2930// GCC requires this function. Taken from MutekH.
    3031////////////////////////////////////////////////////////////////////////////////////////
    31 inline void * memset(void *dst, int s, size_t count)
    32 {
    33 /*
    34   int8_t s = _s;
    35   const reg_t v = (uint8_t)s * (reg_t)0x0101010101010101LL;
    36   int8_t *a = dst;
    37   reg_t *r;
     32inline void * memset(void * dst, int s, size_t count) {
     33    char * a = (char *) dst;
     34    while (count--){
     35        *a++ = (char)s;
     36    }
     37    return dst;
     38}
    3839
    39   // align
    40   while ( ((uintptr_t *)a & reg_t_log2_m1) && count )
    41     count--, *a++ = s;
    4240
    43   size_t ucount = count & reg_t_log2_m1;
    44   count &= ~reg_t_log2_m1;
     41// Local Variables:
     42// tab-width: 4
     43// c-basic-offset: 4
     44// c-file-offsets:((innamespace . 0)(inline-open . 0))
     45// indent-tabs-mode: nil
     46// End:
     47// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
    4548
    46   for (r = (reg_t*)a; count; count -= sizeof(reg_t))
    47       *r++ = v;
    48 
    49   for (a = (int8_t*)r; ucount; ucount--)
    50       *a++ = s;
    51 
    52 */
    53         char *a = (char *) dst;
    54         while (count--){
    55                 *a++ = (char)s;
    56         }
    57 
    58         return dst;
    59 }
  • soft/giet_vm/libs/libsrl/srl_sched_wait.c

    r178 r228  
    2828#define DECLARE_WAIT(name, cmp)                                 \
    2929                                                                \
    30     void srl_sched_wait_##name( void *addr, sint32_t val )              \
    31     {                                                                   \
    32                 srl_dcache_flush_addr(addr);                                                    \
    33         if ( ((sint32_t)*((unsigned int *)addr)) cmp val )              \
    34         return;                                                 \
    35         do {                                                    \
    36             srl_sched_wait_priv(100);??                                                 \
    37                         srl_dcache_flush_addr(addr);                                            \
    38         } while (((sint32_t)*((unsigned int*)addr)) cmp val );  \
    39     }
     30void srl_sched_wait_##name(void * addr, sint32_t val) {         \
     31    srl_dcache_flush_addr(addr);                                \
     32    if (((sint32_t) * ((unsigned int *) addr)) cmp val)         \
     33    return;                                                     \
     34    do {                                                        \
     35        srl_sched_wait_priv(100);??                             \
     36        srl_dcache_flush_addr(addr);                            \
     37    } while (((sint32_t) * ((unsigned int *) addr)) cmp val);   \
     38}
    4039
    4140
     
    5352DECLARE_WAIT(gt, >)
    5453
    55 //TODO
    56 void srl_sched_wait_priv(uint32_t date )
    57 {
    58         do{
    59                 context_switch();
    60         }while (srl_cycle_count() > date);
     54    //TODO
     55void srl_sched_wait_priv(uint32_t date) {
     56    do {
     57        context_switch();
     58    } while (srl_cycle_count() > date);
    6159}
    6260
    63 void srl_sleep_cycles( uint32_t n )
    64 {
    65         uint32_t next_run_to = srl_cycle_count()+n;
     61void srl_sleep_cycles(uint32_t n) {
     62    uint32_t next_run_to = srl_cycle_count() + n;
    6663
    67         while(srl_cycle_count() < next_run_to)
    68                 srl_sched_wait_priv(next_run_to);
     64    while (srl_cycle_count() < next_run_to) {
     65        srl_sched_wait_priv(next_run_to);
     66    }
    6967}
    7068
     69
     70// Local Variables:
     71// tab-width: 4
     72// c-basic-offset: 4
     73// c-file-offsets:((innamespace . 0)(inline-open . 0))
     74// indent-tabs-mode: nil
     75// End:
     76// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     77
  • soft/giet_vm/libs/libsrl/srl_sched_wait.h

    r160 r228  
    3535
    3636
    37 void srl_sleep_cycles( unsigned int n );
     37void srl_sleep_cycles(unsigned int n);
    3838
    3939#endif
     40
     41
     42// Local Variables:
     43// tab-width: 4
     44// c-basic-offset: 4
     45// c-file-offsets:((innamespace . 0)(inline-open . 0))
     46// indent-tabs-mode: nil
     47// End:
     48// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     49
  • soft/giet_vm/libs/mwmr_channel.c

    r207 r228  
    1919// can be used to get the virtual base address of the channel from it's name.
    2020//
    21 // An MWMR transaction transfer an integer number of items, and an item is
     21// An MWMR transaction transfer    an integer number of items, and an item is
    2222// an integer number of unsigned int (32 bits words).
    2323// The max number of words that can be stored in a MWMR channel is defined by the
     
    3939// If the lock is already taken a fixed delay is introduced before retry.
    4040//////////////////////////////////////////////////////////////////////////////
    41 void mwmr_lock_acquire(unsigned int* lock_address)
    42 {
    43     register unsigned int*      plock = lock_address;
    44     register unsigned int       delay = 100;
     41void mwmr_lock_acquire(unsigned int * lock_address) {
     42    register unsigned int * plock = lock_address;
     43    register unsigned int delay = 100;
    4544    asm volatile (
    46             "mwmr_lock_try:                                     \n"
    47             "ll   $2,    0(%0)                          \n" /* $2 <= lock current value */
    48             "bnez $2,    mwmr_lock_delay        \n" /* retry after delay if lock busy */
    49             "li   $3,    1                                      \n" /* $3 <= argument for sc */
    50             "sc   $3,    0(%0)                          \n" /* try to get lock */
    51             "bnez $3,    mwmr_lock_ok           \n" /* exit if atomic */
    52             "mwmr_lock_delay:                           \n"
     45            "mwmr_lock_try:                    \n"
     46            "ll   $2,    0(%0)                \n" /* $2 <= lock current value */
     47            "bnez $2,    mwmr_lock_delay    \n" /* retry after delay if lock busy */
     48            "li   $3,    1                    \n" /* $3 <= argument for sc */
     49            "sc   $3,    0(%0)                \n" /* try to get lock */
     50            "bnez $3,    mwmr_lock_ok        \n" /* exit if atomic */
     51            "mwmr_lock_delay:                \n"
    5352            "move $4,    %1                 \n" /* $4 <= delay */
    5453            "mwmr_lock_loop:                \n"
    55             "beqz $4,    mwmr_lock_loop         \n" /* test end delay */
    56             "addi $4,    $4,  -1                        \n" /* $4 <= $4 - 1 */
    57             "j           mwmr_lock_try          \n" /* retry ll */
    58             "nop                                                        \n"
    59             "mwmr_lock_ok:                                      \n"
     54            "beqz $4,    mwmr_lock_loop        \n" /* test end delay */
     55            "addi $4,    $4,  -1            \n" /* $4 <= $4 - 1 */
     56            "j           mwmr_lock_try        \n" /* retry ll */
     57            "nop                            \n"
     58            "mwmr_lock_ok:                    \n"
    6059            :
    6160            :"r"(plock), "r"(delay)
    6261            :"$2", "$3", "$4");
    6362}
    64 //////////////////////////////////////////////////////////////////////////////
    65 //         nb_mwmr_write()
     63
     64
     65//////////////////////////////////////////////////////////////////////////////
     66//       nb_mwmr_write()
    6667// This is a non-blocking function.
    6768// The nitems parameter is the number of items to be transfered.
     
    7273// the number of read items (it can be 0).
    7374//////////////////////////////////////////////////////////////////////////////
    74 unsigned int nb_mwmr_write( mwmr_channel_t*     mwmr,
    75                             unsigned int*               buffer,
    76                             unsigned int                nitems )
    77 {
    78     unsigned int        x;
    79     unsigned int        spaces;         // number of empty slots (in words)
    80     unsigned int        nwords;         // requested transfer length (in words)
    81     unsigned int    depth;              // channel depth (in words)
    82     unsigned int    width;              // channel width (in words)
    83     unsigned int    sts;        // channel sts
    84     unsigned int    ptw;        // channel ptw
    85 
    86     if(nitems == 0) return 0;
     75unsigned int nb_mwmr_write(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems) {
     76    unsigned int x;
     77    unsigned int spaces; // number of empty slots (in words)
     78    unsigned int nwords; // requested transfer length (in words)
     79    unsigned int depth;  // channel depth (in words)
     80    unsigned int width;  // channel width (in words)
     81    unsigned int sts;    // channel sts
     82    unsigned int ptw;    // channel ptw
     83
     84    if (nitems == 0) {
     85        return 0;
     86    }
    8787
    8888    // get the lock
    89     mwmr_lock_acquire( &mwmr->lock );
     89    mwmr_lock_acquire(&mwmr->lock);
    9090
    9191    // access fifo status
    92     depth  = mwmr->depth;
    93     width  = mwmr->width;
    94     sts    = mwmr->sts;
    95     ptw    = mwmr->ptw;
     92    depth = mwmr->depth;
     93    width = mwmr->width;
     94    sts = mwmr->sts;
     95    ptw = mwmr->ptw;
    9696    spaces = depth - sts;
    9797    nwords = width * nitems;
    9898
    99     if( spaces >= nwords )      // transfer nitems, release lock and return
    100     {
    101         for ( x = 0 ; x < nwords ; x++ ) 
    102         {
     99    if (spaces >= nwords) { // transfer nitems, release lock and return
     100        for (x = 0; x < nwords; x++) {
    103101            mwmr->data[ptw] = buffer[x];
    104             if ( (ptw + 1) == depth ) ptw = 0;
    105             else                      ptw = ptw + 1;
    106         }
    107         mwmr->sts  = mwmr->sts + nwords;
    108         mwmr->ptw  = ptw;
     102            if ((ptw + 1) == depth) {
     103                ptw = 0;
     104            }
     105            else {
     106                ptw = ptw + 1;
     107            }
     108        }
     109        mwmr->sts = mwmr->sts + nwords;
     110        mwmr->ptw = ptw;
    109111        mwmr->lock = 0;
    110112        return nitems;
    111113    }
    112    
    113     else if ( spaces < width )  // release lock and return
    114     {
     114    else if (spaces < width) {
     115        // release lock and return
    115116        mwmr->lock = 0;
    116117        return 0;
    117118    }
    118     else        // transfer as many items as possible, release lock and return
    119     {
    120         nwords = (spaces/width) * width;        // integer number of items
    121         for ( x = 0 ; x < nwords ; x++ ) 
    122         {
     119    else {
     120        // transfer as many items as possible, release lock and return
     121        nwords = (spaces / width) * width;    // integer number of items
     122        for (x = 0; x < nwords; x++) {
    123123            mwmr->data[ptw] = buffer[x];
    124             if ( (ptw + 1) == depth ) ptw = 0;
    125             else                      ptw = ptw + 1;
    126         }
    127         mwmr->sts  = sts + nwords;
    128         mwmr->ptw  = ptw;
    129         mwmr->lock = 0;
    130         return (nwords/width);
     124            if ((ptw + 1) == depth) {
     125                ptw = 0;
     126            }
     127            else {
     128                ptw = ptw + 1;
     129            }
     130        }
     131        mwmr->sts = sts + nwords;
     132        mwmr->ptw = ptw;
     133        mwmr->lock = 0;
     134        return (nwords / width);
    131135    }
    132136} // end nb_mwmr_write()
    133137
    134 //////////////////////////////////////////////////////////////////////////////
    135 //      mwmr_write()
     138
     139//////////////////////////////////////////////////////////////////////////////
     140//    mwmr_write()
    136141// This blocking function returns only when the transfer is completed.
    137142// The nitems parameter is the number of items to be transfered.
     
    142147// after a random delay.
    143148//////////////////////////////////////////////////////////////////////////////
    144 void mwmr_write( mwmr_channel_t*        mwmr,
    145                  unsigned int*          buffer,
    146                  unsigned int           nitems )
    147 {
    148     unsigned int        x;
    149     unsigned int        spaces;         // number of empty slots (in words)
    150     unsigned int        nwords;         // requested transfer length (in words)
    151     unsigned int    depth;              // channel depth (in words)
    152     unsigned int    width;              // channel width (in words)
    153     unsigned int    sts;        // channel sts
    154     unsigned int    ptw;        // channel ptw
    155 
    156     if(nitems == 0) return;
    157 
    158     while(1)
    159     {
     149void mwmr_write(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems) {
     150    unsigned int x;
     151    unsigned int spaces; // number of empty slots (in words)
     152    unsigned int nwords; // requested transfer length (in words)
     153    unsigned int depth;  // channel depth (in words)
     154    unsigned int width;  // channel width (in words)
     155    unsigned int sts;    // channel sts
     156    unsigned int ptw;    // channel ptw
     157
     158    if (nitems == 0) {
     159        return;
     160    }
     161
     162    while (1) {
    160163        // get the lock
    161164        mwmr_lock_acquire(&mwmr->lock);
    162165
    163166        // compute spaces and nwords
    164         depth  = mwmr->depth;
    165         width  = mwmr->width;
    166         sts    = mwmr->sts;
    167         ptw    = mwmr->ptw;
     167        depth = mwmr->depth;
     168        width = mwmr->width;
     169        sts  = mwmr->sts;
     170        ptw  = mwmr->ptw;
    168171        spaces = depth - sts;
    169172        nwords = width * nitems;
    170173
    171         if( spaces >= nwords )  // write nwords, release lock and return
    172         {
    173             for ( x = 0 ; x < nwords ; x++ ) 
    174             {
     174        if (spaces >= nwords) {
     175            // write nwords, release lock and return
     176            for (x = 0; x < nwords; x++) {
    175177                mwmr->data[ptw] = buffer[x];
    176                 if ( (ptw + 1) == depth ) ptw = 0;
    177                 else                      ptw = ptw + 1;
    178             }
    179             mwmr->ptw  = ptw;
    180             mwmr->sts  = sts + nwords;
     178                if ((ptw + 1) == depth) {
     179                    ptw = 0;
     180                }
     181                else {
     182                    ptw = ptw + 1;
     183                }
     184            }
     185            mwmr->ptw = ptw;
     186            mwmr->sts = sts + nwords;
    181187            mwmr->lock = 0;
    182188            return;
    183189        }
    184         else if ( spaces < width )      // release lock and retry after delay
    185         {
    186             mwmr->lock = 0;
    187             for ( x = giet_rand()>>8 ; x > 0 ; x-- ) asm volatile ( "nop" );
    188         }
    189         else    // write as many items as possible, release lock and retry after delay
    190         {
    191             nwords = (spaces/width) * width;  // integer number of items
    192             for ( x = 0 ; x < nwords ; x++ ) 
    193             {
     190        else if (spaces < width) {
     191            // release lock and retry after delay
     192            mwmr->lock = 0;
     193        }
     194        else {
     195            // write as many items as possible, release lock and retry after delay
     196            nwords = (spaces / width) * width;  // integer number of items
     197            for (x = 0; x < nwords; x++) {
    194198                mwmr->data[ptw] = buffer[x];
    195                 if ( (ptw + 1) == depth ) ptw = 0;
    196                 else                      ptw = ptw + 1;
    197             }
    198             mwmr->sts  = sts + nwords;
    199             mwmr->ptw  = ptw;
    200             buffer     = buffer + nwords;
    201             nitems     = nitems - (nwords/width);
    202             mwmr->lock = 0;
    203         }
    204         // random delay before retry
    205         for ( x = giet_rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" );
     199                if ((ptw + 1) == depth) {
     200                    ptw = 0;
     201                }
     202                else {
     203                    ptw = ptw + 1;
     204                }
     205            }
     206            mwmr->sts = sts + nwords;
     207            mwmr->ptw = ptw;
     208            buffer = buffer + nwords;
     209            nitems = nitems - (nwords/width);
     210            mwmr->lock = 0;
     211        }
     212        giet_context_switch();
    206213    }
    207214} // end mwmr_write()
    208215
    209 //////////////////////////////////////////////////////////////////////////////
    210 //         nb_mwmr_read()
     216
     217//////////////////////////////////////////////////////////////////////////////
     218//       nb_mwmr_read()
    211219// This is a non-blocking function.
    212220// The nitems parameter is the number of items to be transfered.
     
    217225// the number of read items (it can be 0).
    218226//////////////////////////////////////////////////////////////////////////////
    219 unsigned int nb_mwmr_read( mwmr_channel_t*      mwmr,
    220                            unsigned int*                buffer,
    221                            unsigned int                 nitems )
    222 {
    223     unsigned int        x;
    224     unsigned int        nwords;         // requested transfer length (in words)
    225     unsigned int    depth;              // channel depth (in words)
    226     unsigned int    width;              // channel width (in words)
    227     unsigned int    sts;        // channel sts
    228     unsigned int    ptr;        // channel ptr
    229 
    230     if(nitems == 0) return 0;
     227unsigned int nb_mwmr_read(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems) {
     228    unsigned int x;
     229    unsigned int nwords; // requested transfer length (in words)
     230    unsigned int depth;  // channel depth (in words)
     231    unsigned int width;  // channel width (in words)
     232    unsigned int sts;    // channel sts
     233    unsigned int ptr;    // channel ptr
     234
     235    if (nitems == 0) {
     236        return 0;
     237    }
    231238
    232239    // get the lock
    233     mwmr_lock_acquire( &mwmr->lock );
     240    mwmr_lock_acquire(&mwmr->lock);
    234241
    235242    // access fifo status
    236     depth  = mwmr->depth;
    237     width  = mwmr->width;
    238     sts    = mwmr->sts;
    239     ptr    = mwmr->ptr;
     243    depth = mwmr->depth;
     244    width = mwmr->width;
     245    sts = mwmr->sts;
     246    ptr = mwmr->ptr;
    240247    nwords = width * nitems;
    241248
    242     if( sts >= nwords )         // transfer nitems, release lock and return
    243     {
    244         for ( x = 0 ; x < nwords ; x++ ) 
    245         {
     249    if (sts >= nwords) {
     250        // transfer nitems, release lock and return
     251        for (x = 0; x < nwords; x++) {
    246252            buffer[x] = mwmr->data[ptr];
    247             if ( (ptr + 1) == depth ) ptr = 0;
    248             else                      ptr = ptr + 1;
    249         }
    250         mwmr->sts  = mwmr->sts - nwords;
    251         mwmr->ptr  = ptr;
     253            if ((ptr + 1) == depth) {
     254                ptr = 0;
     255            }
     256            else {
     257                ptr = ptr + 1;
     258            }
     259        }
     260        mwmr->sts = mwmr->sts - nwords;
     261        mwmr->ptr = ptr;
    252262        mwmr->lock = 0;
    253263        return nitems;
    254264    }
    255    
    256     else if ( sts < width )     // release lock and return
    257     {
     265    else if (sts < width) {
     266        // release lock and return
    258267        mwmr->lock = 0;
    259268        return 0;
    260269    }
    261     else        // transfer as many items as possible, release lock and return
    262     {
    263         nwords = (sts/width) * width;   // integer number of items
    264         for ( x = 0 ; x < nwords ; x++ ) 
    265         {
     270    else {
     271        // transfer as many items as possible, release lock and return
     272        nwords = (sts / width) * width; // integer number of items
     273        for (x = 0 ; x < nwords ; x++) {
    266274            buffer[x] = mwmr->data[ptr];
    267             if ( (ptr + 1) == depth ) ptr = 0;
    268             else                      ptr = ptr + 1;
    269         }
    270         mwmr->sts  = sts - nwords;
    271         mwmr->ptr  = ptr;
    272         mwmr->lock = 0;
    273         return (nwords/width);
    274     }
    275 } // nb_mwmr_read()
    276 
    277 //////////////////////////////////////////////////////////////////////////////
    278 //      mwmr_read()
     275            if ((ptr + 1) == depth) {
     276                ptr = 0;
     277            }
     278            else {
     279                ptr = ptr + 1;
     280            }
     281        }
     282        mwmr->sts = sts - nwords;
     283        mwmr->ptr = ptr;
     284        mwmr->lock = 0;
     285        return (nwords / width);
     286    }
     287} // nb_mwmr_read()
     288
     289
     290//////////////////////////////////////////////////////////////////////////////
     291//    mwmr_read()
    279292// This blocking function returns only when the transfer is completed.
    280293// The nitems parameter is the number of items to be transfered.
     
    285298// after a random delay.
    286299//////////////////////////////////////////////////////////////////////////////
    287 void mwmr_read( mwmr_channel_t*         mwmr,
    288                 unsigned int*           buffer,
    289                 unsigned int            nitems )
    290 {
    291     unsigned int        x;
    292     unsigned int        nwords;         // requested transfer length (in words)
    293     unsigned int    depth;              // channel depth (in words)
    294     unsigned int    width;              // channel width (in words)
    295     unsigned int    sts;        // channel sts
    296     unsigned int    ptr;        // channel ptr
    297 
    298     if(nitems == 0) return;
    299 
    300     while(1)
    301     {
     300void mwmr_read( mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems) {
     301    unsigned int x;
     302    unsigned int nwords; // requested transfer length (in words)
     303    unsigned int depth;  // channel depth (in words)
     304    unsigned int width;  // channel width (in words)
     305    unsigned int sts;    // channel sts
     306    unsigned int ptr;    // channel ptr
     307
     308    if (nitems == 0) {
     309        return;
     310    }
     311
     312    while (1) {
    302313        // get the lock
    303         mwmr_lock_acquire( &mwmr->lock );
     314        mwmr_lock_acquire(&mwmr->lock);
    304315
    305316        // compute nwords
    306         depth  = mwmr->depth;
    307         width  = mwmr->width;
    308         sts    = mwmr->sts;
    309         ptr    = mwmr->ptr;
     317        depth = mwmr->depth;
     318        width = mwmr->width;
     319        sts = mwmr->sts;
     320        ptr = mwmr->ptr;
    310321        nwords = width * nitems;
    311322
    312         if( sts >= nwords )     // read nwords, release lock and return
    313         {
    314             for ( x = 0 ; x < nwords ; x++ ) 
    315             {
     323        if (sts >= nwords) {
     324            // read nwords, release lock and return
     325            for (x = 0; x < nwords; x++) {
    316326                buffer[x] = mwmr->data[ptr];
    317                 if ( (ptr + 1) == depth ) ptr = 0;
    318                 else                      ptr = ptr + 1;
    319             }
    320             mwmr->sts  = mwmr->sts - nwords;
    321             mwmr->ptr  = ptr;
     327                if ((ptr + 1) == depth) {
     328                    ptr = 0;
     329                }
     330                else {
     331                    ptr = ptr + 1;
     332                }
     333            }
     334            mwmr->sts = mwmr->sts - nwords;
     335            mwmr->ptr = ptr;
    322336            mwmr->lock = 0;
    323337            return;
    324338        }
    325         else if ( sts < width ) // release lock and retry after delay
    326         {
    327             mwmr->lock = 0;
    328             for ( x = giet_rand()>>8 ; x > 0 ; x-- ) asm volatile ( "nop" );
    329         }
    330         else    // read as many items as possible, release lock and retry after delay
    331         {
    332             nwords = (sts/width) * width;       // integer number of items
    333             for ( x = 0 ; x < nwords ; x++ ) 
    334             {
     339        else if (sts < width) {
     340            // release lock and retry after delay
     341            mwmr->lock = 0;
     342        }
     343        else {   // read as many items as possible, release lock and retry after delay
     344            nwords = (sts / width) * width; // integer number of items
     345            for (x = 0; x < nwords; x++) {
    335346                buffer[x] = mwmr->data[ptr];
    336                 if ( (ptr + 1) == depth ) ptr = 0;
    337                 else                      ptr = ptr + 1;
    338             }
    339             mwmr->sts  = sts - nwords;
    340             mwmr->ptr  = ptr;
    341             buffer     = buffer + nwords;
    342             nitems     = nitems - (nwords/width);
    343             mwmr->lock = 0;
    344         }
    345         // random delay before retry
    346         for ( x = giet_rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" );
     347                if ((ptr + 1) == depth) {
     348                    ptr = 0;
     349                }
     350                else {
     351                    ptr = ptr + 1;
     352                }
     353            }
     354            mwmr->sts = sts - nwords;
     355            mwmr->ptr = ptr;
     356            buffer = buffer + nwords;
     357            nitems = nitems - (nwords/width);
     358            mwmr->lock = 0;
     359        }
     360        giet_context_switch();
    347361    }
    348362} // end mwmr_read()
    349363
    350364
     365// Local Variables:
     366// tab-width: 4
     367// c-basic-offset: 4
     368// c-file-offsets:((innamespace . 0)(inline-open . 0))
     369// indent-tabs-mode: nil
     370// End:
     371// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     372
  • soft/giet_vm/libs/mwmr_channel.h

    r200 r228  
    1616
    1717typedef struct mwmr_channel_s {
    18     unsigned int        ptr;                    // index of the first valid data word
    19     unsigned int        ptw;                    // index of the first empty slot
    20     unsigned int        sts;                    // number of words available
    21     unsigned int        lock;                   // exclusive access lock
    22     unsigned int        depth;                  // max number of words in the channel
    23     unsigned int        width;                  // number of words in an item   
    24     unsigned int        data[1018];             // circular buffer
     18    unsigned int ptr;        // index of the first valid data word
     19    unsigned int ptw;        // index of the first empty slot
     20    unsigned int sts;        // number of words available
     21    unsigned int lock;       // exclusive access lock
     22    unsigned int depth;      // max number of words in the channel
     23    unsigned int width;      // number of words in an item     
     24    unsigned int data[1018]; // circular buffer
    2525} mwmr_channel_t;
    2626
     
    2929//////////////////////////////////////////////////////////////////////////////
    3030
    31 void mwmr_write( mwmr_channel_t*        mwmr,
    32                  unsigned int*          buffer,
    33                  unsigned int           nitems );
     31void mwmr_write(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems);
     32void mwmr_read(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems);
    3433
    35 void mwmr_read( mwmr_channel_t*         mwmr,
    36                 unsigned int*           buffer,
    37                 unsigned int            nitems );
    3834#endif
    3935
     36// Local Variables:
     37// tab-width: 4
     38// c-basic-offset: 4
     39// c-file-offsets:((innamespace . 0)(inline-open . 0))
     40// indent-tabs-mode: nil
     41// End:
     42// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     43
  • soft/giet_vm/libs/spin_lock.c

    r189 r228  
    2828// If the lock is already taken a random delay is introduced before retry.
    2929///////////////////////////////////////////////////////////////////////////////////
    30 void lock_acquire( giet_lock_t* lock )
    31 {
    32     unsigned int*       plock = &lock->value;
    33  
     30void lock_acquire(giet_lock_t * lock) {
     31    unsigned int * plock = &lock->value;
     32
    3433    asm volatile (
    35             "giet_lock_try:                                     \n"
    36             "ll   $2,    0(%0)                          \n" /* $2 <= lock current value */
    37             "bnez $2,    giet_lock_delay        \n" /* retry if lock already taken */
    38             "li   $3,    1                                      \n" /* $3 <= argument for sc */
    39             "sc   $3,    0(%0)                          \n" /* try to get lock */
    40             "bnez $3,    giet_lock_ok           \n" /* exit if atomic */
     34            "giet_lock_try:                 \n"
     35            "ll   $2,    0(%0)              \n" /* $2 <= lock current value */
     36            "bnez $2,    giet_lock_delay    \n" /* retry if lock already taken */
     37            "li   $3,    1                  \n" /* $3 <= argument for sc */
     38            "sc   $3,    0(%0)              \n" /* try to get lock */
     39            "bnez $3,    giet_lock_ok       \n" /* exit if atomic */
    4140
    42             "giet_lock_delay:                           \n"
    43             "jal  giet_rand                                 \n" /* giet_rand() system call */
    44             "nop                                                        \n"
    45             "andi $4,   $2,     0xFF                    \n"     /* $4 <= delay < 256 cycles */
     41            "giet_lock_delay:               \n"
     42            "jal  giet_rand                 \n" /* giet_rand() system call */
     43            "nop                            \n"
     44            "andi $4,    $2,    0xFF        \n" /* $4 <= delay < 256 cycles */
    4645
    47             "giet_lock_loop:                            \n"
    48             "addi $4,    $4,  -1                        \n" /* $4 <= $4 - 1 */
    49             "beqz $4,    giet_lock_loop         \n" /* test end delay */
    50             "nop                                                        \n"
    51             "j           giet_lock_try          \n" /* retry */
    52             "nop                                                        \n"
    53             "giet_lock_ok:                                      \n"
     46            "giet_lock_loop:                \n"
     47            "addi $4,    $4,  -1            \n" /* $4 <= $4 - 1 */
     48            "beqz $4,    giet_lock_loop     \n" /* test end delay */
     49            "nop                            \n"
     50            "j           giet_lock_try      \n" /* retry */
     51            "nop                            \n"
     52            "giet_lock_ok:                  \n"
    5453            :
    5554            :"r"(plock)
    5655            :"$2", "$3", "$4");
    57 }
     56}
     57
    5858
    5959//////////////////////////////////////////////////////////////////////////////
    6060// lock_release()
    6161//////////////////////////////////////////////////////////////////////////////
    62 void lock_release( giet_lock_t* lock)
    63 {
     62void lock_release(giet_lock_t * lock) {
    6463    lock->value = 0;
    6564}
    6665
     66
     67// Local Variables:
     68// tab-width: 4
     69// c-basic-offset: 4
     70// c-file-offsets:((innamespace . 0)(inline-open . 0))
     71// indent-tabs-mode: nil
     72// End:
     73// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     74
  • soft/giet_vm/libs/spin_lock.h

    r189 r228  
    1515
    1616typedef struct giet_lock_s {
    17     char                        name[32];       // lock name
    18     unsigned int        value;      // taken if value != 0
     17    char name[32];      // lock name
     18    unsigned int value; // taken if value != 0
    1919} giet_lock_t;
    2020
     
    2323//////////////////////////////////////////////////////////////////////////////
    2424
    25 void lock_acquire( giet_lock_t* lock );
    26 
    27 void lock_release( giet_lock_t* lock );
     25void lock_acquire(giet_lock_t * lock);
     26void lock_release(giet_lock_t * lock);
    2827
    2928#endif
    3029
     30// Local Variables:
     31// tab-width: 4
     32// c-basic-offset: 4
     33// c-file-offsets:((innamespace . 0)(inline-open . 0))
     34// indent-tabs-mode: nil
     35// End:
     36// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     37
  • soft/giet_vm/libs/srl.h

    r200 r228  
    1313
    1414#include "libsrl/srl_public_types.h"
    15 //#include "libsrl/srl_private_types.h"
    16 
    1715#include "libsrl/srl_lock.h"
    1816#include "libsrl/srl_mwmr.h"
     
    2018#include "libsrl/srl_barrier.h"
    2119#include "libsrl/srl_memspace.h"
    22 
    2320#include "libsrl/srl_hw_helpers.h"
    24 
    2521#include "libsrl/srl_args.h"
    26 
    27 //kernel use!
    28 //#include "libsrl/srl_mwmr_sys.h"
    2922
    3023
  • soft/giet_vm/libs/stdio.c

    r218 r228  
    2121#define SYSCALL_GCD_WRITE       0x06
    2222#define SYSCALL_GCD_READ        0x07
     23#define SYSCALL_TASK_ID         0x09
    2324#define SYSCALL_CTX_SWITCH      0x0D
    2425#define SYSCALL_EXIT            0x0E
     
    3233#define SYSCALL_IOC_READ        0x16
    3334#define SYSCALL_IOC_COMPLETED   0x17
    34 #define SYSCALL_VOBJ_GET_VBASE  0x1A
     35#define SYSCALL_VOBJ_GET_VBASE  0x1A
    3536#define SYSCALL_NIC_WRITE       0x1B
    3637#define SYSCALL_NIC_READ        0x1C
     
    4344// and tells GCC what has been modified by system call execution.
    4445//////////////////////////////////////////////////////////////////////////////////
    45 static inline unsigned int sys_call( unsigned int call_no,
    46                                      unsigned int arg_0,
    47                                      unsigned int arg_1,
    48                                      unsigned int arg_2,
    49                                      unsigned int arg_3)
    50 {
     46static inline unsigned int sys_call(unsigned int call_no,
     47        unsigned int arg_0,
     48        unsigned int arg_1,
     49        unsigned int arg_2,
     50        unsigned int arg_3) {
    5151    register unsigned int reg_no_and_output asm("v0") = call_no;
    52     register unsigned int reg_a0            asm("a0") = arg_0;
    53     register unsigned int reg_a1            asm("a1") = arg_1;
    54     register unsigned int reg_a2            asm("a2") = arg_2;
    55     register unsigned int reg_a3            asm("a3") = arg_3;
     52    register unsigned int reg_a0 asm("a0") = arg_0;
     53    register unsigned int reg_a1 asm("a1") = arg_1;
     54    register unsigned int reg_a2 asm("a2") = arg_2;
     55    register unsigned int reg_a3 asm("a3") = arg_3;
    5656
    5757    asm volatile(
     
    5959            : "=r" (reg_no_and_output)  /* output argument */
    6060            : "r" (reg_a0),             /* input arguments */
    61               "r" (reg_a1),
    62               "r" (reg_a2),
    63               "r" (reg_a3),
    64               "r" (reg_no_and_output)
     61            "r" (reg_a1),
     62            "r" (reg_a2),
     63            "r" (reg_a3),
     64            "r" (reg_no_and_output)
    6565            : "memory",
    6666            /* These persistant registers will be saved on the stack by the
     
    8383}
    8484
    85 /////   MIPS32 related system calls  /////
     85/////     MIPS32 related system calls  /////
    8686
    8787////////////////////////////////////////////////////////////////////////////////////
     
    9090// This function returns the processor identifier.
    9191////////////////////////////////////////////////////////////////////////////////////
    92 unsigned int giet_procid()
    93 {
    94     return sys_call(SYSCALL_PROCID,
    95                     0, 0, 0, 0);
    96 }
     92unsigned int giet_procid() {
     93    return sys_call(SYSCALL_PROCID, 0, 0, 0, 0);
     94}
     95
     96
    9797////////////////////////////////////////////////////////////////////////////////////
    9898// giet_proctime()
     
    100100// This function returns the local processor time (clock cycles since boot)
    101101////////////////////////////////////////////////////////////////////////////////////
    102 unsigned int giet_proctime()
    103 {
    104     return sys_call(SYSCALL_PROCTIME,
    105                     0, 0, 0, 0);
    106 }
    107 
    108 //////  TTY device related system calls /////
     102unsigned int giet_proctime() {
     103    return sys_call(SYSCALL_PROCTIME, 0, 0, 0, 0);
     104}
     105
     106
     107//////     TTY device related system calls /////
    109108
    110109////////////////////////////////////////////////////////////////////////////////////
     
    116115// - Returns 1 if the character has been written, 0 otherwise.
    117116////////////////////////////////////////////////////////////////////////////////////
    118 unsigned int giet_tty_putc(char byte)
    119 {
    120     return sys_call(SYSCALL_TTY_WRITE,
    121                     (unsigned int)(&byte),
    122                     1,
    123                     0,0);
    124 }
     117unsigned int giet_tty_putc(char byte) {
     118    return sys_call(SYSCALL_TTY_WRITE, (unsigned int) (&byte), 1, 0, 0);
     119}
     120
     121
    125122////////////////////////////////////////////////////////////////////////////////////
    126123// giet_tty_puts()
     
    132129// - Returns the number of written characters.
    133130////////////////////////////////////////////////////////////////////////////////////
    134 unsigned int giet_tty_puts(char *buf)
    135 {
     131unsigned int giet_tty_puts(char * buf) {
    136132    unsigned int length = 0;
    137     while (buf[length] != 0)
    138     {
     133    while (buf[length] != 0) {
    139134        length++;
    140135    }
    141     return sys_call(SYSCALL_TTY_WRITE,
    142                     (unsigned int)buf,
    143                     length,
    144                     0,0);
    145 }
     136    return sys_call(SYSCALL_TTY_WRITE, (unsigned int) buf, length, 0, 0);
     137}
     138
     139
    146140////////////////////////////////////////////////////////////////////////////////////
    147141// giet_tty_putw()
     
    152146// Returns the number of written characters (should be equal to ten).
    153147////////////////////////////////////////////////////////////////////////////////////
    154 unsigned int giet_tty_putw(unsigned int val)
    155 {
     148unsigned int giet_tty_putw(unsigned int val) {
    156149    char buf[10];
    157150    unsigned int i;
    158     for (i = 0; i < 10; i++)
    159     {
    160         buf[9-i] = (val % 10) + 0x30;
     151    for (i = 0; i < 10; i++) {
     152        buf[9 - i] = (val % 10) + 0x30;
    161153        val = val / 10;
    162154    }
    163     return sys_call(SYSCALL_TTY_WRITE,
    164                     (unsigned int)buf,
    165                     10,
    166                     0,0);
    167 }
     155    return sys_call(SYSCALL_TTY_WRITE, (unsigned int) buf, 10, 0, 0);
     156}
     157
     158
    168159////////////////////////////////////////////////////////////////////////////////////
    169160// giet_tty_getc()
     
    174165// - Returns 0 when completed.
    175166////////////////////////////////////////////////////////////////////////////////////
    176 unsigned int giet_tty_getc(char *byte)
    177 {
     167unsigned int giet_tty_getc(char * byte) {
    178168    unsigned int ret = 0;
    179     while (ret == 0)
    180     {
    181         ret = sys_call(SYSCALL_TTY_READ,
    182                        (unsigned int)byte,
    183                        1,
    184                        0,0);
     169    while (ret == 0) {
     170        ret = sys_call(SYSCALL_TTY_READ, (unsigned int)byte, 1, 0, 0);
    185171    }
    186172    return 0;
    187173}
     174
     175
    188176////////////////////////////////////////////////////////////////////////////////////
    189177// giet_tty_gets()
     
    201189//   removed from the target buffer.
    202190////////////////////////////////////////////////////////////////////////////////////
    203 unsigned int giet_tty_gets( char*                       buf,
    204                             unsigned int        bufsize )
    205 {
     191unsigned int giet_tty_gets(char * buf, unsigned int bufsize) {
    206192    unsigned int ret;
    207193    unsigned char byte;
    208194    unsigned int index = 0;
    209195
    210     while (index < (bufsize - 1))
    211     {
     196    while (index < (bufsize - 1)) {
    212197        do {
    213             ret = sys_call(SYSCALL_TTY_READ,
    214                            (unsigned int)(&byte),
    215                            1,
    216                            0,0);
     198            ret = sys_call(SYSCALL_TTY_READ, (unsigned int) (&byte), 1, 0, 0);
    217199        } while (ret != 1);
    218200
    219         if ( byte == 0x0A )
     201        if (byte == 0x0A) {
    220202            break; /* LF */
    221         else if ((byte == 0x7F) && (index > 0))
     203        }
     204        else if ((byte == 0x7F) && (index > 0)) {
    222205            index--; /* DEL */
    223         else
    224         {
     206        }
     207        else {
    225208            buf[index] = byte;
    226209            index++;
     
    230213    return 0;
    231214}
     215
     216
    232217////////////////////////////////////////////////////////////////////////////////////
    233218// giet_tty_getw()
     
    248233//   bits range, the zero value is returned.
    249234////////////////////////////////////////////////////////////////////////////////////
    250 unsigned int giet_tty_getw(unsigned int *val)
    251 {
     235unsigned int giet_tty_getw(unsigned int * val) {
    252236    unsigned char buf[32];
    253237    unsigned char byte;
     
    260244    unsigned int ret;
    261245
    262     while (done == 0)
    263     {
     246    while (done == 0) {
    264247        do {
    265             ret = sys_call(SYSCALL_TTY_READ,
    266                            (unsigned int)(&byte),
    267                            1,
    268                            0,0);
     248            ret = sys_call(SYSCALL_TTY_READ, (unsigned int) (&byte), 1, 0, 0);
    269249        } while (ret != 1);
    270250
    271         if ((byte > 0x2F) && (byte < 0x3A)) /* decimal character */
    272         {
     251        if ((byte > 0x2F) && (byte < 0x3A)) {
     252            /* decimal character */
    273253            buf[max] = byte;
    274254            max++;
    275255            giet_tty_putc(byte);
    276256        }
    277         else if ((byte == 0x0A) || (byte == 0x0D)) /* LF or CR character */
    278         {
     257        else if ((byte == 0x0A) || (byte == 0x0D)) {
     258            /* LF or CR character */
    279259            done = 1;
    280260        }
    281         else if (byte == 0x7F) /* DEL character */
    282         {
    283             if (max > 0)
    284             {
     261        else if (byte == 0x7F) {
     262            /* DEL character */
     263            if (max > 0) {
    285264                max--; /* cancel the character */
    286265                giet_tty_putc(0x08);
     
    289268            }
    290269        }
    291         if (max == 32) /* decimal string overflow */
    292         {
    293             for (i = 0; i < max; i++) /* cancel the string */
    294             {
     270        if (max == 32) {
     271            /* decimal string overflow */
     272            for (i = 0; i < max; i++) {
     273                /* cancel the string */
    295274                giet_tty_putc(0x08);
    296275                giet_tty_putc(0x20);
     
    304283
    305284    /* string conversion */
    306     for (i = 0; i < max; i++)
    307     {
     285    for (i = 0; i < max; i++) {
    308286        dec = dec * 10 + (buf[i] - 0x30);
    309         if (dec < save)
     287        if (dec < save) {
    310288            overflow = 1;
     289        }
    311290        save = dec;
    312291    }
    313292
    314293    /* check overflow */
    315     if (overflow == 0)
    316     {
     294    if (overflow == 0) {
    317295        *val = dec; /* return decimal value */
    318296    }
    319     else
    320     {
    321         for (i = 0; i < max; i++) /* cancel the string */
    322         {
     297    else {
     298        for (i = 0; i < max; i++) {
     299            /* cancel the string */
    323300            giet_tty_putc(0x08);
    324301            giet_tty_putc(0x20);
     
    330307    return 0;
    331308}
     309
     310
    332311////////////////////////////////////////////////////////////////////////////////////
    333312// giet_tty_printf()
     
    344323// - Returns 0 if success, > 0 if error.
    345324////////////////////////////////////////////////////////////////////////////////////
    346 unsigned int giet_tty_printf(char *format, ...)
    347 {
     325unsigned int giet_tty_printf(char * format, ...) {
    348326    va_list ap;
    349327    va_start(ap, format);
     
    354332    while (*format) {
    355333        unsigned int i;
    356         for (i = 0; format[i] && format[i] != '%'; i++)
    357             ;
     334        for (i = 0; format[i] && format[i] != '%'; i++);
    358335        if (i) {
    359             ret = sys_call(SYSCALL_TTY_WRITE,
    360                     (unsigned int)format,
    361                     i,
    362                     0,0);
    363             if (ret != i)
     336            ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int) format, i, 0, 0);
     337            if (ret != i) {
    364338                return 1; /* return error */
     339            }
    365340            format += i;
    366341        }
     
    377352
    378353    {
    379         int         val = va_arg(ap, long);
    380         char            buf[20];
    381         char*          pbuf;
    382         unsigned int        len = 0;
    383         static const char   HexaTab[] = "0123456789ABCDEF";
    384         unsigned int        i;
     354        int val = va_arg(ap, long);
     355        char buf[20];
     356        char * pbuf;
     357        unsigned int len = 0;
     358        static const char HexaTab[] = "0123456789ABCDEF";
     359        unsigned int i;
    385360
    386361        switch (*format++) {
     
    393368                if (val < 0) {
    394369                    val = -val;
    395                     ret = sys_call(SYSCALL_TTY_WRITE,
    396                             (unsigned int)"-",
    397                             1,
    398                             0,0);
    399                     if (ret != 1)
     370                    ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int)"-", 1, 0, 0);
     371                    if (ret != 1) {
    400372                        return 1; /* return error */
     373                    }
    401374                }
    402375            case ('u'):             /* decimal unsigned integer */
    403                 for( i=0 ; i<10 ; i++) {
    404                     buf[9-i] = HexaTab[val % 10];
    405                     if (!(val /= 10)) break;
     376                for(i = 0; i < 10; i++) {
     377                    buf[9 - i] = HexaTab[val % 10];
     378                    if (!(val /= 10)) {
     379                        break;
     380                    }
    406381                }
    407                 len =  i+1;
    408                 pbuf = &buf[9-i];
     382                len =  i + 1;
     383                pbuf = &buf[9 - i];
    409384                break;
    410385            case ('x'):             /* hexadecimal integer */
    411                 ret = sys_call(SYSCALL_TTY_WRITE,
    412                         (unsigned int)"0x",
    413                         2,
    414                         0,0);
    415                 if (ret != 2)
     386                ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int) "0x", 2, 0, 0);
     387                if (ret != 2) {
    416388                    return 1; /* return error */
    417                 for( i=0 ; i<8 ; i++) {
    418                     buf[7-i] = HexaTab[val % 16U];
    419                     if (!(val /= 16U)) break;
    420389                }
    421                 len =  i+1;
    422                 pbuf = &buf[7-i];
     390                for(i = 0; i < 8; i++) {
     391                    buf[7 - i] = HexaTab[val % 16U];
     392                    if (!(val /= 16U)) {
     393                        break;
     394                    }
     395                }
     396                len =  i + 1;
     397                pbuf = &buf[7 - i];
    423398                break;
    424399            case ('s'):             /* string */
    425400                {
    426                     char *str = (char*)val;
    427                     while ( str[len] ) len++;
    428                     pbuf = (char*)val;
     401                    char * str = (char *) val;
     402                    while (str[len]) {
     403                        len++;
     404                    }
     405                    pbuf = (char *) val;
    429406                }
    430407                break;
     
    433410        }
    434411
    435         ret = sys_call(SYSCALL_TTY_WRITE,
    436                 (unsigned int)pbuf,
    437                 len,
    438                 0,0);
    439         if (ret != len)
     412        ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int) pbuf, len, 0, 0);
     413        if (ret != len) {
    440414            return 1;
     415        }
    441416        goto printf_text;
    442417    }
     
    453428// - Returns 0 if success, > 0 if error.
    454429//////////////////////////////////////////////////////////////////////////////////
    455 unsigned int giet_timer_start()
    456 {
    457     return sys_call(SYSCALL_TIMER_START,
    458                    0,0,0,0);
    459 }
     430unsigned int giet_timer_start() {
     431    return sys_call(SYSCALL_TIMER_START, 0, 0, 0, 0);
     432}
     433
     434
    460435//////////////////////////////////////////////////////////////////////////////////
    461436// giet_timer_stop()
     
    464439// - Returns 0 if success, > 0 if error.
    465440//////////////////////////////////////////////////////////////////////////////////
    466 unsigned int giet_timer_stop()
    467 {
    468     return sys_call(SYSCALL_TIMER_STOP,
    469                    0,0,0,0);
    470 }
     441unsigned int giet_timer_stop() {
     442    return sys_call(SYSCALL_TIMER_STOP, 0, 0, 0, 0);
     443}
     444
    471445
    472446/////  GCD (Greatest Common Divider) related system calls
     
    483457// - Returns 0 if success, > 0 if error.
    484458//////////////////////////////////////////////////////////////////////////////////
    485 unsigned int giet_gcd_set_opa(unsigned int val)
    486 {
    487     return sys_call(SYSCALL_GCD_WRITE,
    488                     GCD_OPA,
    489                     val,
    490                     0, 0);
    491 }
    492 //////////////////////////////////////////////////////////////////////////////////
    493 //      giet_gcd_set_opb()
     459unsigned int giet_gcd_set_opa(unsigned int val) {
     460    return sys_call(SYSCALL_GCD_WRITE, GCD_OPA, val, 0, 0);
     461}
     462
     463
     464//////////////////////////////////////////////////////////////////////////////////
     465//     giet_gcd_set_opb()
    494466//////////////////////////////////////////////////////////////////////////////////
    495467// This function sets operand B in the GCD coprocessor.
    496468// - Returns 0 if success, > 0 if error.
    497469//////////////////////////////////////////////////////////////////////////////////
    498 unsigned int giet_gcd_set_opb(unsigned int val)
    499 {
    500     return sys_call(SYSCALL_GCD_WRITE,
    501                     GCD_OPB,
    502                     val,
    503                     0, 0);
    504 }
    505 //////////////////////////////////////////////////////////////////////////////////
    506 //      giet_gcd_start()
     470unsigned int giet_gcd_set_opb(unsigned int val) {
     471    return sys_call(SYSCALL_GCD_WRITE, GCD_OPB, val, 0, 0);
     472}
     473
     474
     475//////////////////////////////////////////////////////////////////////////////////
     476//     giet_gcd_start()
    507477//////////////////////////////////////////////////////////////////////////////////
    508478// This function starts the computation in the GCD coprocessor.
    509479// - Returns 0 if success, > 0 if error.
    510480//////////////////////////////////////////////////////////////////////////////////
    511 unsigned int giet_gcd_start()
    512 {
    513     return sys_call(SYSCALL_GCD_WRITE,
    514                     GCD_START,
    515                     0, 0, 0);
    516 }
    517 //////////////////////////////////////////////////////////////////////////////////
    518 //      giet_gcd_get_status()
     481unsigned int giet_gcd_start() {
     482    return sys_call(SYSCALL_GCD_WRITE, GCD_START, 0, 0, 0);
     483}
     484
     485
     486//////////////////////////////////////////////////////////////////////////////////
     487//     giet_gcd_get_status()
    519488//////////////////////////////////////////////////////////////////////////////////
    520489// This function gets the status fromn the GCD coprocessor.
    521490// - The value is 0 when the coprocessor is idle (computation completed).
    522491//////////////////////////////////////////////////////////////////////////////////
    523 unsigned int giet_gcd_get_status(unsigned int *val)
    524 {
    525     return sys_call(SYSCALL_GCD_READ,
    526             GCD_STATUS,
    527             (unsigned int)val,
    528             0, 0);
    529 }
    530 //////////////////////////////////////////////////////////////////////////////////
    531 //      giet_gcd_get_result()
     492unsigned int giet_gcd_get_status(unsigned int * val) {
     493    return sys_call(SYSCALL_GCD_READ, GCD_STATUS, (unsigned int) val, 0, 0);
     494}
     495
     496
     497//////////////////////////////////////////////////////////////////////////////////
     498//     giet_gcd_get_result()
    532499//////////////////////////////////////////////////////////////////////////////////
    533500// This function gets the result of the computation from the GCD coprocessor.
    534501//////////////////////////////////////////////////////////////////////////////////
    535 unsigned int giet_gcd_get_result(unsigned int *val)
    536 {
    537     return sys_call(SYSCALL_GCD_READ,
    538             GCD_OPA,
    539             (unsigned int)val,
    540             0, 0);
    541 }
     502unsigned int giet_gcd_get_result(unsigned int * val) {
     503    return sys_call(SYSCALL_GCD_READ, GCD_OPA, (unsigned int) val, 0, 0);
     504}
     505
    542506
    543507///// Block device related system calls  /////
    544508
    545509//////////////////////////////////////////////////////////////////////////////////
    546 //      giet_ioc_write()
     510//     giet_ioc_write()
    547511//////////////////////////////////////////////////////////////////////////////////
    548512// Transfer data from a memory buffer to a file on the block_device.
     
    552516// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    553517//////////////////////////////////////////////////////////////////////////////////
    554 unsigned int giet_ioc_write( unsigned int       lba,
    555                              void*                      buffer,
    556                              unsigned int       count)
    557 {
    558     return sys_call(SYSCALL_IOC_WRITE,
    559             lba,
    560             (unsigned int)buffer,
    561             count,
    562             0);
    563 }
     518unsigned int giet_ioc_write( unsigned int lba, void * buffer, unsigned int count) {
     519    return sys_call(SYSCALL_IOC_WRITE, lba, (unsigned int) buffer, count, 0);
     520}
     521
     522
    564523//////////////////////////////////////////////////////////////////////////////////
    565524// giet_ioc_read()
     
    571530// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    572531//////////////////////////////////////////////////////////////////////////////////
    573 unsigned int giet_ioc_read( unsigned int                lba,
    574                             void*                               buffer,
    575                             unsigned int                count )
    576 {
    577     return sys_call(SYSCALL_IOC_READ,
    578             lba,
    579             (unsigned int)buffer,
    580             count,
    581             0);
    582 }
     532unsigned int giet_ioc_read(unsigned int lba, void * buffer, unsigned int count) {
     533    return sys_call(SYSCALL_IOC_READ, lba, (unsigned int) buffer, count, 0);
     534}
     535
     536
    583537//////////////////////////////////////////////////////////////////////////////////
    584538// giet_ioc_completed()
     
    587541// successfully completed, and returns 1 if an address error has been detected.
    588542//////////////////////////////////////////////////////////////////////////////////
    589 unsigned int giet_ioc_completed()
    590 {
    591     return sys_call(SYSCALL_IOC_COMPLETED,
    592             0, 0, 0, 0);
    593 }
     543unsigned int giet_ioc_completed() {
     544    return sys_call(SYSCALL_IOC_COMPLETED, 0, 0, 0, 0);
     545}
     546
    594547
    595548/////  Frame buffer device related system calls  /////
     
    605558// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    606559//////////////////////////////////////////////////////////////////////////////////
    607 unsigned int giet_fb_sync_write( unsigned int   offset,
    608                                  void*                  buffer,
    609                                  unsigned int   length )
    610 {
    611     return sys_call(SYSCALL_FB_SYNC_WRITE,
    612             offset,
    613             (unsigned int)buffer,
    614             length,
    615             0);
    616 }
     560unsigned int giet_fb_sync_write(unsigned int offset, void * buffer, unsigned int length) {
     561    return sys_call(SYSCALL_FB_SYNC_WRITE, offset, (unsigned int) buffer, length, 0);
     562}
     563
     564
    617565//////////////////////////////////////////////////////////////////////////////////
    618566// giet_fb_sync_read()
     
    625573// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    626574//////////////////////////////////////////////////////////////////////////////////
    627 unsigned int giet_fb_sync_read( unsigned int    offset,
    628                                 void*                   buffer,
    629                                 unsigned int    length )
    630 {
    631     return sys_call(SYSCALL_FB_SYNC_READ,
    632             offset,
    633             (unsigned int)buffer,
    634             length,
    635             0);
    636 }
     575unsigned int giet_fb_sync_read(unsigned int offset, void * buffer, unsigned int length) {
     576    return sys_call(SYSCALL_FB_SYNC_READ, offset, (unsigned int) buffer, length, 0);
     577}
     578
     579
    637580//////////////////////////////////////////////////////////////////////////////////
    638581// giet_fb_write()
     
    647590// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    648591//////////////////////////////////////////////////////////////////////////////////
    649 unsigned int giet_fb_write( unsigned int        offset,
    650                             void*               buffer,
    651                             unsigned int        length )
    652 {
    653     return sys_call(SYSCALL_FB_WRITE,
    654             offset,
    655             (unsigned int)buffer,
    656             length,
    657             0);
    658 }
     592unsigned int giet_fb_write(unsigned int offset, void * buffer, unsigned int length) {
     593    return sys_call(SYSCALL_FB_WRITE, offset, (unsigned int) buffer, length, 0);
     594}
     595
     596
    659597//////////////////////////////////////////////////////////////////////////////////
    660598// giet_fb_read()
     
    669607// - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space).
    670608//////////////////////////////////////////////////////////////////////////////////
    671 unsigned int giet_fb_read( unsigned int         offset,
    672                            void*                buffer,
    673                            unsigned int         length )
    674 {
    675     return sys_call(SYSCALL_FB_READ,
    676                     offset,
    677                     (unsigned int)buffer,
    678                     length,
    679                     0);
    680 }
     609unsigned int giet_fb_read(unsigned int offset, void * buffer, unsigned int length) {
     610    return sys_call(SYSCALL_FB_READ, offset, (unsigned int) buffer, length, 0);
     611}
     612
     613
    681614//////////////////////////////////////////////////////////////////////////////////
    682615// giet_fb_completed()
     
    685618// - Returns 0 if success, > 0 if error.
    686619//////////////////////////////////////////////////////////////////////////////////
    687 unsigned int giet_fb_completed()
    688 {
    689     return sys_call(SYSCALL_FB_COMPLETED,
    690                     0, 0, 0, 0);
    691 }
     620unsigned int giet_fb_completed() {
     621    return sys_call(SYSCALL_FB_COMPLETED, 0, 0, 0, 0);
     622}
     623
    692624
    693625//////////////////////////////////////////////////////////////////////////////////
     
    704636//////////////////////////////////////////////////////////////////////////////////
    705637
    706 unsigned int giet_nic_write( unsigned int       offset,
    707                              void*              buffer,
    708                              unsigned int       length )
    709 {
    710     return sys_call(SYSCALL_NIC_WRITE,
    711             offset,
    712             (unsigned int)buffer,
    713             length,
    714             0);
    715 }
     638unsigned int giet_nic_write(unsigned int offset, void * buffer, unsigned int length) {
     639    return sys_call(SYSCALL_NIC_WRITE, offset, (unsigned int) buffer, length, 0);
     640}
     641
    716642
    717643//////////////////////////////////////////////////////////////////////////////////
     
    728654//////////////////////////////////////////////////////////////////////////////////
    729655
    730 unsigned int giet_nic_read( unsigned int        offset,
    731                             void*                   buffer,
    732                             unsigned int        length )
    733 {
    734     return sys_call(SYSCALL_NIC_READ,
    735             offset,
    736             (unsigned int)buffer,
    737             length,
    738             0);
    739 }
     656unsigned int giet_nic_read(unsigned int offset, void * buffer, unsigned int length) {
     657    return sys_call(SYSCALL_NIC_READ, offset, (unsigned int) buffer, length, 0);
     658}
     659
    740660
    741661//////////////////////////////////////////////////////////////////////////////////
     
    745665// - Returns 0 if success, > 0 if error.
    746666//////////////////////////////////////////////////////////////////////////////////
    747 unsigned int giet_nic_completed()
    748 {
    749     return sys_call(SYSCALL_NIC_COMPLETED,
    750                     0, 0, 0, 0);
    751 }
     667unsigned int giet_nic_completed() {
     668    return sys_call(SYSCALL_NIC_COMPLETED, 0, 0, 0, 0);
     669}
     670
    752671
    753672///// Miscellaneous related system calls /////
     
    762681// - Returns the address if success,  0 if error ( not defined or wrong type )
    763682//////////////////////////////////////////////////////////////////////////////////
    764 unsigned int giet_vobj_get_vbase( char*                 vspace_name,
    765                                   char*                 vobj_name,
    766                                   unsigned int  vobj_type,
    767                                   unsigned int* vobj_vaddr )
    768 {
     683unsigned int giet_vobj_get_vbase(char * vspace_name, char * vobj_name, unsigned int vobj_type, unsigned int * vobj_vaddr) {
    769684    return sys_call(SYSCALL_VOBJ_GET_VBASE,
    770                     (unsigned int)vspace_name,
    771                     (unsigned int)vobj_name,
    772                     (unsigned int)vobj_type,
    773                     (unsigned int)vobj_vaddr);
    774 }
     685            (unsigned int) vspace_name,
     686            (unsigned int) vobj_name,
     687            (unsigned int) vobj_type,
     688            (unsigned int) vobj_vaddr);
     689}
     690
    775691
    776692////////////////////////////////////////////////////////////////////////////////////
     
    781697// - Returns 0 if success, > 0 if error ( cluster index too large )
    782698////////////////////////////////////////////////////////////////////////////////////
    783 unsigned int giet_proc_number( unsigned int             cluster_id,
    784                                unsigned int*    buffer )
    785 {
    786     return sys_call(SYSCALL_PROC_NUMBER,
    787                     cluster_id,
    788                     (unsigned int)buffer,
    789                     0, 0);
    790 }
     699unsigned int giet_proc_number(unsigned int cluster_id, unsigned int * buffer) {
     700    return sys_call(SYSCALL_PROC_NUMBER, cluster_id, (unsigned int) buffer, 0, 0);
     701}
     702
    791703
    792704/////  Miscellaneous system calls /////
     
    799711// The task is blocked, but it still consume processor cycles ...
    800712//////////////////////////////////////////////////////////////////////////////////
    801 void giet_exit()
    802 {
    803     sys_call(SYSCALL_EXIT,
    804              0, 0, 0, 0);
    805 }
     713void giet_exit() {
     714    sys_call(SYSCALL_EXIT, 0, 0, 0, 0);
     715}
     716
     717
    806718///////////////////////////////////////////////////////////////////////////////////
    807719// giet_rand()
     
    809721// count. This value is comprised between 0 & 65535.
    810722///////////////////////////////////////////////////////////////////////////////////
    811 unsigned int giet_rand()
    812 {
    813     unsigned int x = sys_call(SYSCALL_PROCTIME,
    814                               0, 0, 0, 0);
    815     if((x & 0xF) > 7)
     723unsigned int giet_rand() {
     724    unsigned int x = sys_call(SYSCALL_PROCTIME, 0, 0, 0, 0);
     725    if ((x & 0xF) > 7) {
    816726        return (x*x & 0xFFFF);
    817     else
     727    }
     728    else {
    818729        return (x*x*x & 0xFFFF);
    819 }
    820 //////////////////////////////////////////////////////////////////////////////////
    821 // giet_ctx_switch()
     730    }
     731}
     732
     733
     734//////////////////////////////////////////////////////////////////////////////////
     735// giet_context_switch()
    822736// The user task calling this function is descheduled and
    823737// the processor is allocated to another task.
    824738//////////////////////////////////////////////////////////////////////////////////
    825 unsigned int giet_ctx_switch()
    826 {
    827     return sys_call(SYSCALL_CTX_SWITCH,
    828                     0, 0, 0, 0);
    829 }
    830 
    831 
     739unsigned int giet_context_switch() {
     740    return sys_call(SYSCALL_CTX_SWITCH, 0, 0, 0, 0);
     741}
     742
     743//////////////////////////////////////////////////////////////////////////////////
     744// giet_get_task_id()
     745// The user task calling this function is descheduled and
     746// the processor is allocated to another task.
     747//////////////////////////////////////////////////////////////////////////////////
     748unsigned int giet_task_id() {
     749    return sys_call(SYSCALL_TASK_ID, 0, 0, 0, 0);
     750}
     751
     752
     753// Local Variables:
     754// tab-width: 4
     755// c-basic-offset: 4
     756// c-file-offsets:((innamespace . 0)(inline-open . 0))
     757// indent-tabs-mode: nil
     758// End:
     759// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     760
  • soft/giet_vm/libs/stdio.h

    r218 r228  
    1515/* TTY device related functions */
    1616unsigned int giet_tty_putc(char byte);
    17 unsigned int giet_tty_puts(char *buf);
     17unsigned int giet_tty_puts(char * buf);
    1818unsigned int giet_tty_putw(unsigned int val);
    19 unsigned int giet_tty_getc_no_irq(char *byte);
    20 unsigned int giet_tty_getc(char *byte);
    21 unsigned int giet_tty_gets(char *buf, unsigned int bufsize);
    22 unsigned int giet_tty_getw(unsigned int *val);
    23 unsigned int giet_tty_printf(char *format,...);
     19unsigned int giet_tty_getc_no_irq(char * byte);
     20unsigned int giet_tty_getc(char * byte);
     21unsigned int giet_tty_gets(char * buf, unsigned int bufsize);
     22unsigned int giet_tty_getw(unsigned int * val);
     23unsigned int giet_tty_printf(char * format,...);
    2424
    2525/* GCD coprocessor related functions */
     
    2727unsigned int giet_gcd_set_opb(unsigned int val);
    2828unsigned int giet_gcd_start();
    29 unsigned int giet_gcd_get_result(unsigned int *val);
    30 unsigned int giet_gcd_get_status(unsigned int *val);
     29unsigned int giet_gcd_get_result(unsigned int * val);
     30unsigned int giet_gcd_get_status(unsigned int * val);
    3131
    3232/* Block device related functions */
    33 unsigned int giet_ioc_read( unsigned int        lba,
    34                             void*                       buffer,
    35                             unsigned int        count);
    36 unsigned int giet_ioc_write(unsigned int        lba,
    37                             void*                       buffer,
    38                             unsigned int        count);
     33unsigned int giet_ioc_read(unsigned int lba, void * buffer, unsigned int count);
     34unsigned int giet_ioc_write(unsigned int lba, void * buffer, unsigned int count);
    3935unsigned int giet_ioc_completed();
    4036
    4137/* Frame buffer device related functions */
    42 unsigned int giet_fb_sync_read( unsigned int    offset,
    43                                 void*                   buffer,
    44                                 unsigned int    length );
    45 unsigned int giet_fb_sync_write(unsigned int    offset,
    46                                 void*                   buffer,
    47                                 unsigned int    length );
    48 unsigned int giet_fb_read(      unsigned int    offset,
    49                                 void*                   buffer,
    50                                 unsigned int    length );
    51 unsigned int giet_fb_write(     unsigned int    offset,
    52                                 void*                   buffer,
    53                                 unsigned int    length );
    54 unsigned int giet_nic_write(    unsigned int    offset,
    55                                 void*           buffer,
    56                                 unsigned int    length );
    57 unsigned int giet_nic_read(     unsigned int    offset,
    58                                 void*           buffer,
    59                                 unsigned int    length );
     38unsigned int giet_fb_sync_read(unsigned int offset, void * buffer, unsigned int length );
     39unsigned int giet_fb_sync_write(unsigned int offset, void * buffer, unsigned int length);
     40unsigned int giet_fb_read(unsigned int offset, void * buffer, unsigned int length);
     41unsigned int giet_fb_write(unsigned int offset, void * buffer, unsigned int length);
     42unsigned int giet_nic_write(unsigned int offset, void * buffer, unsigned int length);
     43unsigned int giet_nic_read(unsigned int offset, void * buffer, unsigned int length);
    6044unsigned int giet_fb_completed();
    6145unsigned int giet_nic_completed();
    6246
    6347/* Misc */
    64 unsigned int giet_vobj_get_vbase( char* vspace_name,
    65                                   char* vobj_name,
    66                                   unsigned int vobj_type,
    67                                   unsigned int* vobj_vaddr );
    68 void         giet_exit();
     48unsigned int giet_vobj_get_vbase(char * vspace_name, char * vobj_name, unsigned int vobj_type, unsigned int * vobj_vaddr);
     49void giet_exit();
    6950unsigned int giet_rand();
    70 unsigned int giet_ctx_switch();
     51unsigned int giet_context_switch();
     52unsigned int giet_task_id();
    7153unsigned int giet_procnumber();
    7254
    7355#endif
    7456
     57// Local Variables:
     58// tab-width: 4
     59// c-basic-offset: 4
     60// c-file-offsets:((innamespace . 0)(inline-open . 0))
     61// indent-tabs-mode: nil
     62// End:
     63// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     64
  • soft/giet_vm/libs/utils.c

    r201 r228  
    44// GCC requires this function. Taken from MutekH.
    55////////////////////////////////////////////////////////////////////////////////////////
    6 void *memcpy(void *_dst, const void *_src, unsigned int size)
    7 {
    8     unsigned int *dst = _dst;
    9     const unsigned int *src = _src;
    10     if ( ! ((unsigned int)dst & 3) && ! ((unsigned int)src & 3) )
     6void * memcpy(void *_dst, const void * _src, unsigned int size) {
     7    unsigned int * dst = _dst;
     8    const unsigned int * src = _src;
     9    if (!((unsigned int) dst & 3) && ! ((unsigned int) src & 3) ) {
    1110        while (size > 3) {
    1211            *dst++ = *src++;
    1312            size -= 4;
    1413        }
     14    }
    1515
    16     unsigned char *cdst = (unsigned char*)dst;
    17     unsigned char *csrc = (unsigned char*)src;
     16    unsigned char * cdst = (unsigned char *) dst;
     17    unsigned char * csrc = (unsigned char *) src;
    1818
    1919    while (size--) {
     
    2323}
    2424
     25
    2526////////////////////////////////////////////////////////////////////////////////////////
    2627//  memset()
    2728// GCC requires this function. Taken from MutekH.
    2829////////////////////////////////////////////////////////////////////////////////////////
    29 void * memset(void *dst, int s, unsigned int count)
    30 {
    31         char *a = (char *) dst;
    32         while (count--)
    33                 *a++ = (char)s;
    34         return dst;
     30void * memset(void * dst, int s, unsigned int count) {
     31    char * a = (char *) dst;
     32    while (count--) {
     33        *a++ = (char) s;
     34    }
     35    return dst;
    3536}
     37
     38
     39// Local Variables:
     40// tab-width: 4
     41// c-basic-offset: 4
     42// c-file-offsets:((innamespace . 0)(inline-open . 0))
     43// indent-tabs-mode: nil
     44// End:
     45// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     46
  • soft/giet_vm/libs/utils.h

    r201 r228  
    99#define _UTILS_H
    1010
    11 void*   memcpy( void*                   dst,
    12                 void*                   src,
    13                 unsigned int    size );
     11void * memcpy(void * dst, void * src, unsigned int size);
     12void * memset(void * dst, int s, unsigned int count);
    1413
    15 void * memset( void *dst,
    16                int s,
    17                unsigned int count);
    1814#endif
    1915
     16// Local Variables:
     17// tab-width: 4
     18// c-basic-offset: 4
     19// c-file-offsets:((innamespace . 0)(inline-open . 0))
     20// indent-tabs-mode: nil
     21// End:
     22// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     23
Note: See TracChangeset for help on using the changeset viewer.