Changeset 228 for soft/giet_vm/libs
- Timestamp:
- Feb 12, 2013, 6:33:31 PM (12 years ago)
- Location:
- soft/giet_vm/libs
- Files:
-
- 1 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/libs/barrier.c
r165 r228 15 15 16 16 /////////////////////////////////////////////////////////////////////////////////// 17 // 17 // barrier_init() 18 18 // This function makes a cooperative initialisation of the barrier: 19 19 // several tasks try to initialize the barrier, but the initialisation 20 20 // is done by only one task, using LL/SC instructions. 21 21 /////////////////////////////////////////////////////////////////////////////////// 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; 22 void 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; 27 25 28 26 // parallel initialisation using atomic instructions LL/SC … … 30 28 // no output 31 29 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"); 42 41 } 42 43 43 44 /////////////////////////////////////////////////////////////////////////////////// 44 // 45 // barrier_wait() 45 46 // This blocking function uses LL/SC to decrement the barrier's counter. 46 47 // Then, it uses a busy_waiting mechanism if it is not the last. 47 48 // (because the GIET does not support dynamic task scheduling/descheduling) 48 49 /////////////////////////////////////////////////////////////////////////////////// 49 void barrier_wait( giet_barrier_t* barrier ) 50 { 51 unsigned int* pcount = (unsigned int*)&barrier->count; 50 void barrier_wait(giet_barrier_t * barrier) { 51 unsigned int * pcount = (unsigned int *) &barrier->count; 52 52 unsigned int maxcount = barrier->init; 53 53 unsigned int count; … … 57 57 // - output : counter value 58 58 asm volatile ("_barrier_decrement: \n" 59 60 61 62 63 64 65 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"); 66 66 67 67 // the last task re-initializes the barrier counter to the max value, 68 68 // waking up all other waiting tasks 69 69 70 if (count == 1) // last task71 {70 if (count == 1) { 71 // last task 72 72 *pcount = maxcount; 73 73 } 74 else // other tasks busy-wait75 {74 else { 75 // other tasks busy-wait 76 76 while (*pcount != maxcount) asm volatile ("nop"); 77 77 } 78 78 } 79 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/barrier.h
r165 r228 14 14 15 15 typedef struct giet_barrier_s { 16 char name[32];// barrier name17 unsigned int init;// total number of participants18 unsigned int count;// number of not yet arrived tasks16 char name[32]; // barrier name 17 unsigned int init; // total number of participants 18 unsigned int count; // number of not yet arrived tasks 19 19 } giet_barrier_t; 20 20 … … 23 23 ////////////////////////////////////////////////////////////////////////////// 24 24 25 void barrier_init( giet_barrier_t* barrier, 26 unsigned int value ); 27 28 void barrier_wait( giet_barrier_t* barrier ); 25 void barrier_init(giet_barrier_t * barrier, unsigned int value); 26 void barrier_wait(giet_barrier_t * barrier); 29 27 30 28 #endif 31 29 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 16 16 */ 17 17 ////////////////////////////////////////////////////////////////////////// 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; 18 static inline void * memcpy(void * _dst, const void * _src, unsigned int size) { 19 unsigned int * dst = _dst; 20 const unsigned int * src = _src; 22 21 23 22 /* if source and destination buffer are word-aligned, 24 23 * 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)) { 26 25 while (size > 3) { 27 26 *dst++ = *src++; 28 27 size -= 4; 29 28 } 29 } 30 30 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; 33 33 34 34 /* byte-by-byte copy */ … … 39 39 } 40 40 41 41 42 ////////////////////////////////////////////////////////// 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 43 static 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; 48 49 } 49 50 51 50 52 /** 51 52 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) ) { \ 57 59 giet_tty_printf("assertion (%s) failed on %s:%d !\n", \ 58 #expr, __FILE__, __LINE__ );\59 __abort(); 60 } 60 #expr, __FILE__, __LINE__ ); \ 61 __abort(); \ 62 } \ 61 63 } while(0) 62 64 63 65 /** 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 */ 69 static inline void __abort() { 70 asm volatile ("break 0"); 71 while (1); 71 72 } 72 73 73 74 #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 4 4 5 5 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) 11 11 12 12 … … 14 14 ({ \ 15 15 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)) \ 17 17 { \ 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); \ 22 22 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; \ 27 28 }) 28 29 -
soft/giet_vm/libs/libsrl/srl_barrier.h
r178 r228 23 23 24 24 25 typedef giet_barrier_t * srl_barrier_t;25 typedef giet_barrier_t * srl_barrier_t; 26 26 27 27 #define srl_barrier_wait(bar) barrier_wait(bar) 28 28 29 29 #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 5 5 6 6 /** @this reads a big endian 16 bits value */ 7 # define endian_le16(x) 7 # define endian_le16(x) (x) 8 8 /** @this reads a big endian 32 bits value */ 9 # define endian_le32(x) 9 # define endian_le32(x) (x) 10 10 /** @this reads a big endian 64 bits value */ 11 //# define endian_le64(x) 11 //# define endian_le64(x) (x) 12 12 /** @this reads a little endian 16 bits value */ 13 # define endian_be16(x) 13 # define endian_be16(x) endian_swap16(x) 14 14 /** @this reads a little endian 32 bits value */ 15 # define endian_be32(x) 15 # define endian_be32(x) endian_swap32(x) 16 16 /** @this reads a little endian 64 bits value */ 17 //# define endian_be64(x) 17 //# define endian_be64(x) endian_swap64(x) 18 18 19 19 /** @internal */ 20 static inline uint16_t endian_swap16(uint16_t x) 21 { 22 return (x >> 8) | (x << 8); 20 static inline uint16_t endian_swap16(uint16_t x) { 21 return (x >> 8) | (x << 8); 23 22 } 24 23 24 25 25 /** @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)); 26 static 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)); 32 31 } 33 32 33 34 34 /** @internal *//* 35 static inline uint64_t __endian_swap64(uint64_t x)36 {37 return (((uint64_t)endian_swap32(x ) << 32) |38 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 }*/ 40 40 41 static inline uint32_t srl_uint32_le_to_machine(uint32_t x) 42 { 43 return endian_le32(x); 41 static inline uint32_t srl_uint32_le_to_machine(uint32_t x) { 42 return endian_le32(x); 44 43 } 45 44 46 static inline uint32_t srl_uint32_machine_to_le(uint32_t x) 47 {48 45 46 static inline uint32_t srl_uint32_machine_to_le(uint32_t x) { 47 return endian_le32(x); 49 48 } 50 49 51 static inline uint32_t srl_uint32_be_to_machine(uint32_t x) 52 {53 50 51 static inline uint32_t srl_uint32_be_to_machine(uint32_t x) { 52 return endian_be32(x); 54 53 } 55 54 56 static inline uint32_t srl_uint32_machine_to_be(uint32_t x) 57 {58 55 56 static inline uint32_t srl_uint32_machine_to_be(uint32_t x) { 57 return endian_be32(x); 59 58 } 60 59 61 static inline uint16_t srl_uint16_le_to_machine(uint16_t x) 62 {63 60 61 static inline uint16_t srl_uint16_le_to_machine(uint16_t x) { 62 return endian_le16(x); 64 63 } 65 64 66 static inline uint16_t srl_uint16_machine_to_le(uint16_t x) 67 {68 65 66 static inline uint16_t srl_uint16_machine_to_le(uint16_t x) { 67 return endian_le16(x); 69 68 } 70 69 71 static inline uint16_t srl_uint16_be_to_machine(uint16_t x) 72 {73 70 71 static inline uint16_t srl_uint16_be_to_machine(uint16_t x) { 72 return endian_be16(x); 74 73 } 75 74 76 static inline uint16_t srl_uint16_machine_to_be(uint16_t x) 77 {78 75 76 static inline uint16_t srl_uint16_machine_to_be(uint16_t x) { 77 return endian_be16(x); 79 78 } 80 79 81 80 82 81 #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 12 12 13 13 /** 14 15 */14 Standard API call, expands to nothing for this implementation. 15 */ 16 16 #define srl_busy_cycles(n) do{}while(0) 17 17 18 18 //void useless(void *pointless,...){} 19 19 /** 20 21 */20 @this flushes the cache line containing the address. 21 */ 22 22 //TODO 23 23 #define srl_dcache_flush_addr 0 24 24 25 25 /* 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 */ 34 34 35 35 /** 36 37 */36 @this flushes a memory zone from cache. 37 */ 38 38 //TODO 39 39 //void dcache_flush(const void * addr, size_t size) … … 41 41 42 42 /** 43 44 43 @this waits for at least the given time (in cycles). The actual 44 time spent in this call is not predictable. 45 45 46 47 */48 void srl_sleep_cycles( unsigned int time);46 @param time Number of cycles to wait for 47 */ 48 void srl_sleep_cycles(unsigned int time); 49 49 50 50 /** 51 52 51 @this returns the absolute timestamp counter from the 52 initialization of the platform. 53 53 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 */ 56 static inline unsigned int srl_cycle_count() { 57 return giet_proctime(); 59 58 } 60 59 60 61 61 /** 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 */ 65 static inline void srl_abort() { 66 asm volatile ("break 0"); 67 while (1); 69 68 } 69 70 70 71 71 /** 72 72 * 73 73 */ 74 static inline void srl_exit() 75 { 74 static inline void srl_exit() { 76 75 giet_exit(); 77 76 } 78 77 79 78 #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 23 23 #include "spin_lock.h" 24 24 25 typedef giet_lock_t * srl_lock_t;25 typedef giet_lock_t * srl_lock_t; 26 26 27 27 /** … … 49 49 50 50 #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 1 1 #ifndef SRL_MEMSPACE_H 2 2 #define SRL_MEMSPACE_H 3 4 #include "srl_public_types.h" 5 6 #include <memspace.h> 3 7 4 8 /** … … 12 16 The memspace abstract type. 13 17 */ 14 typedef void* srl_memspace_t; 18 19 20 typedef giet_memspace_t * srl_memspace_t; 15 21 16 22 /** … … 21 27 */ 22 28 #define SRL_MEMSPACE_SIZE(memsp) ((memsp)->size) 29 #define SRL_MEMSPACE_ADDR(memsp) ((memsp)->buffer) 30 23 31 24 32 #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 4 4 #include "mwmr_channel.h" 5 5 6 typedef mwmr_channel_t * srl_mwmr_t;6 typedef mwmr_channel_t * srl_mwmr_t; 7 7 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) 10 10 11 11 12 12 #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 1 2 #include "srl_private_types.h" 2 3 … … 6 7 // GCC requires this function. Taken from MutekH. 7 8 //////////////////////////////////////////////////////////////////////////////////////// 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) ) 9 void * 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) ) 13 13 while (size > 3) { 14 14 *dst++ = *src++; … … 25 25 } 26 26 27 27 28 //////////////////////////////////////////////////////////////////////////////////////// 28 29 // mempcy() 29 30 // GCC requires this function. Taken from MutekH. 30 31 //////////////////////////////////////////////////////////////////////////////////////// 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; 32 inline 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 } 38 39 39 // align40 while ( ((uintptr_t *)a & reg_t_log2_m1) && count )41 count--, *a++ = s;42 40 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 45 48 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 28 28 #define DECLARE_WAIT(name, cmp) \ 29 29 \ 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 } 30 void 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 } 40 39 41 40 … … 53 52 DECLARE_WAIT(gt, >) 54 53 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 55 void srl_sched_wait_priv(uint32_t date) { 56 do { 57 context_switch(); 58 } while (srl_cycle_count() > date); 61 59 } 62 60 63 void srl_sleep_cycles( uint32_t n ) 64 { 65 uint32_t next_run_to = srl_cycle_count()+n; 61 void srl_sleep_cycles(uint32_t n) { 62 uint32_t next_run_to = srl_cycle_count() + n; 66 63 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 } 69 67 } 70 68 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 35 35 36 36 37 void srl_sleep_cycles( unsigned int n);37 void srl_sleep_cycles(unsigned int n); 38 38 39 39 #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 19 19 // can be used to get the virtual base address of the channel from it's name. 20 20 // 21 // An MWMR transaction transfer 21 // An MWMR transaction transfer an integer number of items, and an item is 22 22 // an integer number of unsigned int (32 bits words). 23 23 // The max number of words that can be stored in a MWMR channel is defined by the … … 39 39 // If the lock is already taken a fixed delay is introduced before retry. 40 40 ////////////////////////////////////////////////////////////////////////////// 41 void mwmr_lock_acquire(unsigned int* lock_address) 42 { 43 register unsigned int* plock = lock_address; 44 register unsigned int delay = 100; 41 void mwmr_lock_acquire(unsigned int * lock_address) { 42 register unsigned int * plock = lock_address; 43 register unsigned int delay = 100; 45 44 asm volatile ( 46 "mwmr_lock_try: 47 "ll $2, 0(%0) 48 "bnez $2, mwmr_lock_delay 49 "li $3, 1 50 "sc $3, 0(%0) 51 "bnez $3, mwmr_lock_ok 52 "mwmr_lock_delay: 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" 53 52 "move $4, %1 \n" /* $4 <= delay */ 54 53 "mwmr_lock_loop: \n" 55 "beqz $4, mwmr_lock_loop 56 "addi $4, $4, -1 57 "j mwmr_lock_try 58 "nop 59 "mwmr_lock_ok: 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" 60 59 : 61 60 :"r"(plock), "r"(delay) 62 61 :"$2", "$3", "$4"); 63 62 } 64 ////////////////////////////////////////////////////////////////////////////// 65 // nb_mwmr_write() 63 64 65 ////////////////////////////////////////////////////////////////////////////// 66 // nb_mwmr_write() 66 67 // This is a non-blocking function. 67 68 // The nitems parameter is the number of items to be transfered. … … 72 73 // the number of read items (it can be 0). 73 74 ////////////////////////////////////////////////////////////////////////////// 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; 75 unsigned 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 } 87 87 88 88 // get the lock 89 mwmr_lock_acquire( &mwmr->lock);89 mwmr_lock_acquire(&mwmr->lock); 90 90 91 91 // access fifo status 92 depth 93 width 94 sts 95 ptw 92 depth = mwmr->depth; 93 width = mwmr->width; 94 sts = mwmr->sts; 95 ptw = mwmr->ptw; 96 96 spaces = depth - sts; 97 97 nwords = width * nitems; 98 98 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++) { 103 101 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; 109 111 mwmr->lock = 0; 110 112 return nitems; 111 113 } 112 113 else if ( spaces < width ) // release lock and return 114 { 114 else if (spaces < width) { 115 // release lock and return 115 116 mwmr->lock = 0; 116 117 return 0; 117 118 } 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++) { 123 123 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); 131 135 } 132 136 } // end nb_mwmr_write() 133 137 134 ////////////////////////////////////////////////////////////////////////////// 135 // mwmr_write() 138 139 ////////////////////////////////////////////////////////////////////////////// 140 // mwmr_write() 136 141 // This blocking function returns only when the transfer is completed. 137 142 // The nitems parameter is the number of items to be transfered. … … 142 147 // after a random delay. 143 148 ////////////////////////////////////////////////////////////////////////////// 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 { 149 void 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) { 160 163 // get the lock 161 164 mwmr_lock_acquire(&mwmr->lock); 162 165 163 166 // compute spaces and nwords 164 depth 165 width 166 sts 167 ptw 167 depth = mwmr->depth; 168 width = mwmr->width; 169 sts = mwmr->sts; 170 ptw = mwmr->ptw; 168 171 spaces = depth - sts; 169 172 nwords = width * nitems; 170 173 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++) { 175 177 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; 181 187 mwmr->lock = 0; 182 188 return; 183 189 } 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++) { 194 198 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(); 206 213 } 207 214 } // end mwmr_write() 208 215 209 ////////////////////////////////////////////////////////////////////////////// 210 // nb_mwmr_read() 216 217 ////////////////////////////////////////////////////////////////////////////// 218 // nb_mwmr_read() 211 219 // This is a non-blocking function. 212 220 // The nitems parameter is the number of items to be transfered. … … 217 225 // the number of read items (it can be 0). 218 226 ////////////////////////////////////////////////////////////////////////////// 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; 227 unsigned 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 } 231 238 232 239 // get the lock 233 mwmr_lock_acquire( &mwmr->lock);240 mwmr_lock_acquire(&mwmr->lock); 234 241 235 242 // access fifo status 236 depth 237 width 238 sts 239 ptr 243 depth = mwmr->depth; 244 width = mwmr->width; 245 sts = mwmr->sts; 246 ptr = mwmr->ptr; 240 247 nwords = width * nitems; 241 248 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++) { 246 252 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; 252 262 mwmr->lock = 0; 253 263 return nitems; 254 264 } 255 256 else if ( sts < width ) // release lock and return 257 { 265 else if (sts < width) { 266 // release lock and return 258 267 mwmr->lock = 0; 259 268 return 0; 260 269 } 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++) { 266 274 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() 279 292 // This blocking function returns only when the transfer is completed. 280 293 // The nitems parameter is the number of items to be transfered. … … 285 298 // after a random delay. 286 299 ////////////////////////////////////////////////////////////////////////////// 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 { 300 void 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) { 302 313 // get the lock 303 mwmr_lock_acquire( &mwmr->lock);314 mwmr_lock_acquire(&mwmr->lock); 304 315 305 316 // compute nwords 306 depth 307 width 308 sts 309 ptr 317 depth = mwmr->depth; 318 width = mwmr->width; 319 sts = mwmr->sts; 320 ptr = mwmr->ptr; 310 321 nwords = width * nitems; 311 322 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++) { 316 326 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; 322 336 mwmr->lock = 0; 323 337 return; 324 338 } 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++) { 335 346 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(); 347 361 } 348 362 } // end mwmr_read() 349 363 350 364 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 16 16 17 17 typedef struct mwmr_channel_s { 18 unsigned int ptr;// index of the first valid data word19 unsigned int ptw;// index of the first empty slot20 unsigned int sts;// number of words available21 unsigned int lock;// exclusive access lock22 unsigned int depth;// max number of words in the channel23 unsigned int width; // number of words in an item24 unsigned int data[1018];// circular buffer18 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 25 25 } mwmr_channel_t; 26 26 … … 29 29 ////////////////////////////////////////////////////////////////////////////// 30 30 31 void mwmr_write( mwmr_channel_t* mwmr, 32 unsigned int* buffer, 33 unsigned int nitems ); 31 void mwmr_write(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems); 32 void mwmr_read(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems); 34 33 35 void mwmr_read( mwmr_channel_t* mwmr,36 unsigned int* buffer,37 unsigned int nitems );38 34 #endif 39 35 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 28 28 // If the lock is already taken a random delay is introduced before retry. 29 29 /////////////////////////////////////////////////////////////////////////////////// 30 void lock_acquire( giet_lock_t* lock ) 31 { 32 unsigned int* plock = &lock->value; 33 30 void lock_acquire(giet_lock_t * lock) { 31 unsigned int * plock = &lock->value; 32 34 33 asm volatile ( 35 "giet_lock_try: 36 "ll $2, 0(%0) 37 "bnez $2, giet_lock_delay 38 "li $3, 1 39 "sc $3, 0(%0) 40 "bnez $3, giet_lock_ok 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 */ 41 40 42 "giet_lock_delay: 43 "jal giet_rand 44 "nop 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 */ 46 45 47 "giet_lock_loop: 48 "addi $4, $4, -1 49 "beqz $4, giet_lock_loop 50 "nop 51 "j giet_lock_try 52 "nop 53 "giet_lock_ok: 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" 54 53 : 55 54 :"r"(plock) 56 55 :"$2", "$3", "$4"); 57 } 56 } 57 58 58 59 59 ////////////////////////////////////////////////////////////////////////////// 60 60 // lock_release() 61 61 ////////////////////////////////////////////////////////////////////////////// 62 void lock_release( giet_lock_t* lock) 63 { 62 void lock_release(giet_lock_t * lock) { 64 63 lock->value = 0; 65 64 } 66 65 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 15 15 16 16 typedef struct giet_lock_s { 17 char name[32];// lock name18 unsigned int value;// taken if value != 017 char name[32]; // lock name 18 unsigned int value; // taken if value != 0 19 19 } giet_lock_t; 20 20 … … 23 23 ////////////////////////////////////////////////////////////////////////////// 24 24 25 void lock_acquire( giet_lock_t* lock ); 26 27 void lock_release( giet_lock_t* lock ); 25 void lock_acquire(giet_lock_t * lock); 26 void lock_release(giet_lock_t * lock); 28 27 29 28 #endif 30 29 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 13 13 14 14 #include "libsrl/srl_public_types.h" 15 //#include "libsrl/srl_private_types.h"16 17 15 #include "libsrl/srl_lock.h" 18 16 #include "libsrl/srl_mwmr.h" … … 20 18 #include "libsrl/srl_barrier.h" 21 19 #include "libsrl/srl_memspace.h" 22 23 20 #include "libsrl/srl_hw_helpers.h" 24 25 21 #include "libsrl/srl_args.h" 26 27 //kernel use!28 //#include "libsrl/srl_mwmr_sys.h"29 22 30 23 -
soft/giet_vm/libs/stdio.c
r218 r228 21 21 #define SYSCALL_GCD_WRITE 0x06 22 22 #define SYSCALL_GCD_READ 0x07 23 #define SYSCALL_TASK_ID 0x09 23 24 #define SYSCALL_CTX_SWITCH 0x0D 24 25 #define SYSCALL_EXIT 0x0E … … 32 33 #define SYSCALL_IOC_READ 0x16 33 34 #define SYSCALL_IOC_COMPLETED 0x17 34 #define SYSCALL_VOBJ_GET_VBASE 35 #define SYSCALL_VOBJ_GET_VBASE 0x1A 35 36 #define SYSCALL_NIC_WRITE 0x1B 36 37 #define SYSCALL_NIC_READ 0x1C … … 43 44 // and tells GCC what has been modified by system call execution. 44 45 ////////////////////////////////////////////////////////////////////////////////// 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 { 46 static 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) { 51 51 register unsigned int reg_no_and_output asm("v0") = call_no; 52 register unsigned int reg_a0 53 register unsigned int reg_a1 54 register unsigned int reg_a2 55 register unsigned int reg_a3 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; 56 56 57 57 asm volatile( … … 59 59 : "=r" (reg_no_and_output) /* output argument */ 60 60 : "r" (reg_a0), /* input arguments */ 61 62 63 64 61 "r" (reg_a1), 62 "r" (reg_a2), 63 "r" (reg_a3), 64 "r" (reg_no_and_output) 65 65 : "memory", 66 66 /* These persistant registers will be saved on the stack by the … … 83 83 } 84 84 85 ///// 85 ///// MIPS32 related system calls ///// 86 86 87 87 //////////////////////////////////////////////////////////////////////////////////// … … 90 90 // This function returns the processor identifier. 91 91 //////////////////////////////////////////////////////////////////////////////////// 92 unsigned int giet_procid() 93 { 94 return sys_call(SYSCALL_PROCID, 95 0, 0, 0, 0); 96 } 92 unsigned int giet_procid() { 93 return sys_call(SYSCALL_PROCID, 0, 0, 0, 0); 94 } 95 96 97 97 //////////////////////////////////////////////////////////////////////////////////// 98 98 // giet_proctime() … … 100 100 // This function returns the local processor time (clock cycles since boot) 101 101 //////////////////////////////////////////////////////////////////////////////////// 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 ///// 102 unsigned int giet_proctime() { 103 return sys_call(SYSCALL_PROCTIME, 0, 0, 0, 0); 104 } 105 106 107 ////// TTY device related system calls ///// 109 108 110 109 //////////////////////////////////////////////////////////////////////////////////// … … 116 115 // - Returns 1 if the character has been written, 0 otherwise. 117 116 //////////////////////////////////////////////////////////////////////////////////// 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 } 117 unsigned int giet_tty_putc(char byte) { 118 return sys_call(SYSCALL_TTY_WRITE, (unsigned int) (&byte), 1, 0, 0); 119 } 120 121 125 122 //////////////////////////////////////////////////////////////////////////////////// 126 123 // giet_tty_puts() … … 132 129 // - Returns the number of written characters. 133 130 //////////////////////////////////////////////////////////////////////////////////// 134 unsigned int giet_tty_puts(char *buf) 135 { 131 unsigned int giet_tty_puts(char * buf) { 136 132 unsigned int length = 0; 137 while (buf[length] != 0) 138 { 133 while (buf[length] != 0) { 139 134 length++; 140 135 } 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 146 140 //////////////////////////////////////////////////////////////////////////////////// 147 141 // giet_tty_putw() … … 152 146 // Returns the number of written characters (should be equal to ten). 153 147 //////////////////////////////////////////////////////////////////////////////////// 154 unsigned int giet_tty_putw(unsigned int val) 155 { 148 unsigned int giet_tty_putw(unsigned int val) { 156 149 char buf[10]; 157 150 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; 161 153 val = val / 10; 162 154 } 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 168 159 //////////////////////////////////////////////////////////////////////////////////// 169 160 // giet_tty_getc() … … 174 165 // - Returns 0 when completed. 175 166 //////////////////////////////////////////////////////////////////////////////////// 176 unsigned int giet_tty_getc(char *byte) 177 { 167 unsigned int giet_tty_getc(char * byte) { 178 168 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); 185 171 } 186 172 return 0; 187 173 } 174 175 188 176 //////////////////////////////////////////////////////////////////////////////////// 189 177 // giet_tty_gets() … … 201 189 // removed from the target buffer. 202 190 //////////////////////////////////////////////////////////////////////////////////// 203 unsigned int giet_tty_gets( char* buf, 204 unsigned int bufsize ) 205 { 191 unsigned int giet_tty_gets(char * buf, unsigned int bufsize) { 206 192 unsigned int ret; 207 193 unsigned char byte; 208 194 unsigned int index = 0; 209 195 210 while (index < (bufsize - 1)) 211 { 196 while (index < (bufsize - 1)) { 212 197 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); 217 199 } while (ret != 1); 218 200 219 if ( byte == 0x0A )201 if (byte == 0x0A) { 220 202 break; /* LF */ 221 else if ((byte == 0x7F) && (index > 0)) 203 } 204 else if ((byte == 0x7F) && (index > 0)) { 222 205 index--; /* DEL */ 223 else224 {206 } 207 else { 225 208 buf[index] = byte; 226 209 index++; … … 230 213 return 0; 231 214 } 215 216 232 217 //////////////////////////////////////////////////////////////////////////////////// 233 218 // giet_tty_getw() … … 248 233 // bits range, the zero value is returned. 249 234 //////////////////////////////////////////////////////////////////////////////////// 250 unsigned int giet_tty_getw(unsigned int *val) 251 { 235 unsigned int giet_tty_getw(unsigned int * val) { 252 236 unsigned char buf[32]; 253 237 unsigned char byte; … … 260 244 unsigned int ret; 261 245 262 while (done == 0) 263 { 246 while (done == 0) { 264 247 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); 269 249 } while (ret != 1); 270 250 271 if ((byte > 0x2F) && (byte < 0x3A)) /* decimal character */272 {251 if ((byte > 0x2F) && (byte < 0x3A)) { 252 /* decimal character */ 273 253 buf[max] = byte; 274 254 max++; 275 255 giet_tty_putc(byte); 276 256 } 277 else if ((byte == 0x0A) || (byte == 0x0D)) /* LF or CR character */278 {257 else if ((byte == 0x0A) || (byte == 0x0D)) { 258 /* LF or CR character */ 279 259 done = 1; 280 260 } 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) { 285 264 max--; /* cancel the character */ 286 265 giet_tty_putc(0x08); … … 289 268 } 290 269 } 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 */ 295 274 giet_tty_putc(0x08); 296 275 giet_tty_putc(0x20); … … 304 283 305 284 /* string conversion */ 306 for (i = 0; i < max; i++) 307 { 285 for (i = 0; i < max; i++) { 308 286 dec = dec * 10 + (buf[i] - 0x30); 309 if (dec < save) 287 if (dec < save) { 310 288 overflow = 1; 289 } 311 290 save = dec; 312 291 } 313 292 314 293 /* check overflow */ 315 if (overflow == 0) 316 { 294 if (overflow == 0) { 317 295 *val = dec; /* return decimal value */ 318 296 } 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 */ 323 300 giet_tty_putc(0x08); 324 301 giet_tty_putc(0x20); … … 330 307 return 0; 331 308 } 309 310 332 311 //////////////////////////////////////////////////////////////////////////////////// 333 312 // giet_tty_printf() … … 344 323 // - Returns 0 if success, > 0 if error. 345 324 //////////////////////////////////////////////////////////////////////////////////// 346 unsigned int giet_tty_printf(char *format, ...) 347 { 325 unsigned int giet_tty_printf(char * format, ...) { 348 326 va_list ap; 349 327 va_start(ap, format); … … 354 332 while (*format) { 355 333 unsigned int i; 356 for (i = 0; format[i] && format[i] != '%'; i++) 357 ; 334 for (i = 0; format[i] && format[i] != '%'; i++); 358 335 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) { 364 338 return 1; /* return error */ 339 } 365 340 format += i; 366 341 } … … 377 352 378 353 { 379 int 380 char 381 char *pbuf;382 unsigned int 383 static const char 384 unsigned int 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; 385 360 386 361 switch (*format++) { … … 393 368 if (val < 0) { 394 369 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) { 400 372 return 1; /* return error */ 373 } 401 374 } 402 375 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 } 406 381 } 407 len = i +1;408 pbuf = &buf[9 -i];382 len = i + 1; 383 pbuf = &buf[9 - i]; 409 384 break; 410 385 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) { 416 388 return 1; /* return error */ 417 for( i=0 ; i<8 ; i++) {418 buf[7-i] = HexaTab[val % 16U];419 if (!(val /= 16U)) break;420 389 } 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]; 423 398 break; 424 399 case ('s'): /* string */ 425 400 { 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; 429 406 } 430 407 break; … … 433 410 } 434 411 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) { 440 414 return 1; 415 } 441 416 goto printf_text; 442 417 } … … 453 428 // - Returns 0 if success, > 0 if error. 454 429 ////////////////////////////////////////////////////////////////////////////////// 455 unsigned int giet_timer_start() 456 { 457 return sys_call(SYSCALL_TIMER_START, 458 0,0,0,0); 459 } 430 unsigned int giet_timer_start() { 431 return sys_call(SYSCALL_TIMER_START, 0, 0, 0, 0); 432 } 433 434 460 435 ////////////////////////////////////////////////////////////////////////////////// 461 436 // giet_timer_stop() … … 464 439 // - Returns 0 if success, > 0 if error. 465 440 ////////////////////////////////////////////////////////////////////////////////// 466 unsigned int giet_timer_stop() 467 { 468 return sys_call(SYSCALL_TIMER_STOP, 469 0,0,0,0); 470 } 441 unsigned int giet_timer_stop() { 442 return sys_call(SYSCALL_TIMER_STOP, 0, 0, 0, 0); 443 } 444 471 445 472 446 ///// GCD (Greatest Common Divider) related system calls … … 483 457 // - Returns 0 if success, > 0 if error. 484 458 ////////////////////////////////////////////////////////////////////////////////// 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() 459 unsigned 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() 494 466 ////////////////////////////////////////////////////////////////////////////////// 495 467 // This function sets operand B in the GCD coprocessor. 496 468 // - Returns 0 if success, > 0 if error. 497 469 ////////////////////////////////////////////////////////////////////////////////// 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() 470 unsigned 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() 507 477 ////////////////////////////////////////////////////////////////////////////////// 508 478 // This function starts the computation in the GCD coprocessor. 509 479 // - Returns 0 if success, > 0 if error. 510 480 ////////////////////////////////////////////////////////////////////////////////// 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() 481 unsigned 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() 519 488 ////////////////////////////////////////////////////////////////////////////////// 520 489 // This function gets the status fromn the GCD coprocessor. 521 490 // - The value is 0 when the coprocessor is idle (computation completed). 522 491 ////////////////////////////////////////////////////////////////////////////////// 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() 492 unsigned 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() 532 499 ////////////////////////////////////////////////////////////////////////////////// 533 500 // This function gets the result of the computation from the GCD coprocessor. 534 501 ////////////////////////////////////////////////////////////////////////////////// 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 } 502 unsigned int giet_gcd_get_result(unsigned int * val) { 503 return sys_call(SYSCALL_GCD_READ, GCD_OPA, (unsigned int) val, 0, 0); 504 } 505 542 506 543 507 ///// Block device related system calls ///// 544 508 545 509 ////////////////////////////////////////////////////////////////////////////////// 546 // 510 // giet_ioc_write() 547 511 ////////////////////////////////////////////////////////////////////////////////// 548 512 // Transfer data from a memory buffer to a file on the block_device. … … 552 516 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 553 517 ////////////////////////////////////////////////////////////////////////////////// 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 } 518 unsigned 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 564 523 ////////////////////////////////////////////////////////////////////////////////// 565 524 // giet_ioc_read() … … 571 530 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 572 531 ////////////////////////////////////////////////////////////////////////////////// 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 } 532 unsigned 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 583 537 ////////////////////////////////////////////////////////////////////////////////// 584 538 // giet_ioc_completed() … … 587 541 // successfully completed, and returns 1 if an address error has been detected. 588 542 ////////////////////////////////////////////////////////////////////////////////// 589 unsigned int giet_ioc_completed() 590 { 591 return sys_call(SYSCALL_IOC_COMPLETED, 592 0, 0, 0, 0); 593 } 543 unsigned int giet_ioc_completed() { 544 return sys_call(SYSCALL_IOC_COMPLETED, 0, 0, 0, 0); 545 } 546 594 547 595 548 ///// Frame buffer device related system calls ///// … … 605 558 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 606 559 ////////////////////////////////////////////////////////////////////////////////// 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 } 560 unsigned 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 617 565 ////////////////////////////////////////////////////////////////////////////////// 618 566 // giet_fb_sync_read() … … 625 573 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 626 574 ////////////////////////////////////////////////////////////////////////////////// 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 } 575 unsigned 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 637 580 ////////////////////////////////////////////////////////////////////////////////// 638 581 // giet_fb_write() … … 647 590 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 648 591 ////////////////////////////////////////////////////////////////////////////////// 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 } 592 unsigned 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 659 597 ////////////////////////////////////////////////////////////////////////////////// 660 598 // giet_fb_read() … … 669 607 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 670 608 ////////////////////////////////////////////////////////////////////////////////// 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 } 609 unsigned 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 681 614 ////////////////////////////////////////////////////////////////////////////////// 682 615 // giet_fb_completed() … … 685 618 // - Returns 0 if success, > 0 if error. 686 619 ////////////////////////////////////////////////////////////////////////////////// 687 unsigned int giet_fb_completed() 688 { 689 return sys_call(SYSCALL_FB_COMPLETED, 690 0, 0, 0, 0); 691 } 620 unsigned int giet_fb_completed() { 621 return sys_call(SYSCALL_FB_COMPLETED, 0, 0, 0, 0); 622 } 623 692 624 693 625 ////////////////////////////////////////////////////////////////////////////////// … … 704 636 ////////////////////////////////////////////////////////////////////////////////// 705 637 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 } 638 unsigned 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 716 642 717 643 ////////////////////////////////////////////////////////////////////////////////// … … 728 654 ////////////////////////////////////////////////////////////////////////////////// 729 655 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 } 656 unsigned 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 740 660 741 661 ////////////////////////////////////////////////////////////////////////////////// … … 745 665 // - Returns 0 if success, > 0 if error. 746 666 ////////////////////////////////////////////////////////////////////////////////// 747 unsigned int giet_nic_completed() 748 { 749 return sys_call(SYSCALL_NIC_COMPLETED, 750 0, 0, 0, 0); 751 } 667 unsigned int giet_nic_completed() { 668 return sys_call(SYSCALL_NIC_COMPLETED, 0, 0, 0, 0); 669 } 670 752 671 753 672 ///// Miscellaneous related system calls ///// … … 762 681 // - Returns the address if success, 0 if error ( not defined or wrong type ) 763 682 ////////////////////////////////////////////////////////////////////////////////// 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 { 683 unsigned int giet_vobj_get_vbase(char * vspace_name, char * vobj_name, unsigned int vobj_type, unsigned int * vobj_vaddr) { 769 684 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 775 691 776 692 //////////////////////////////////////////////////////////////////////////////////// … … 781 697 // - Returns 0 if success, > 0 if error ( cluster index too large ) 782 698 //////////////////////////////////////////////////////////////////////////////////// 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 } 699 unsigned 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 791 703 792 704 ///// Miscellaneous system calls ///// … … 799 711 // The task is blocked, but it still consume processor cycles ... 800 712 ////////////////////////////////////////////////////////////////////////////////// 801 void giet_exit() 802 { 803 sys_call(SYSCALL_EXIT, 804 0, 0, 0, 0); 805 } 713 void giet_exit() { 714 sys_call(SYSCALL_EXIT, 0, 0, 0, 0); 715 } 716 717 806 718 /////////////////////////////////////////////////////////////////////////////////// 807 719 // giet_rand() … … 809 721 // count. This value is comprised between 0 & 65535. 810 722 /////////////////////////////////////////////////////////////////////////////////// 811 unsigned int giet_rand() 812 { 813 unsigned int x = sys_call(SYSCALL_PROCTIME, 814 0, 0, 0, 0); 815 if((x & 0xF) > 7) 723 unsigned int giet_rand() { 724 unsigned int x = sys_call(SYSCALL_PROCTIME, 0, 0, 0, 0); 725 if ((x & 0xF) > 7) { 816 726 return (x*x & 0xFFFF); 817 else 727 } 728 else { 818 729 return (x*x*x & 0xFFFF); 819 } 820 ////////////////////////////////////////////////////////////////////////////////// 821 // giet_ctx_switch() 730 } 731 } 732 733 734 ////////////////////////////////////////////////////////////////////////////////// 735 // giet_context_switch() 822 736 // The user task calling this function is descheduled and 823 737 // the processor is allocated to another task. 824 738 ////////////////////////////////////////////////////////////////////////////////// 825 unsigned int giet_ctx_switch() 826 { 827 return sys_call(SYSCALL_CTX_SWITCH, 828 0, 0, 0, 0); 829 } 830 831 739 unsigned 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 ////////////////////////////////////////////////////////////////////////////////// 748 unsigned 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 15 15 /* TTY device related functions */ 16 16 unsigned int giet_tty_putc(char byte); 17 unsigned int giet_tty_puts(char * buf);17 unsigned int giet_tty_puts(char * buf); 18 18 unsigned 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,...);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,...); 24 24 25 25 /* GCD coprocessor related functions */ … … 27 27 unsigned int giet_gcd_set_opb(unsigned int val); 28 28 unsigned int giet_gcd_start(); 29 unsigned int giet_gcd_get_result(unsigned int * val);30 unsigned int giet_gcd_get_status(unsigned int * val);29 unsigned int giet_gcd_get_result(unsigned int * val); 30 unsigned int giet_gcd_get_status(unsigned int * val); 31 31 32 32 /* 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); 33 unsigned int giet_ioc_read(unsigned int lba, void * buffer, unsigned int count); 34 unsigned int giet_ioc_write(unsigned int lba, void * buffer, unsigned int count); 39 35 unsigned int giet_ioc_completed(); 40 36 41 37 /* 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 ); 38 unsigned int giet_fb_sync_read(unsigned int offset, void * buffer, unsigned int length ); 39 unsigned int giet_fb_sync_write(unsigned int offset, void * buffer, unsigned int length); 40 unsigned int giet_fb_read(unsigned int offset, void * buffer, unsigned int length); 41 unsigned int giet_fb_write(unsigned int offset, void * buffer, unsigned int length); 42 unsigned int giet_nic_write(unsigned int offset, void * buffer, unsigned int length); 43 unsigned int giet_nic_read(unsigned int offset, void * buffer, unsigned int length); 60 44 unsigned int giet_fb_completed(); 61 45 unsigned int giet_nic_completed(); 62 46 63 47 /* 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(); 48 unsigned int giet_vobj_get_vbase(char * vspace_name, char * vobj_name, unsigned int vobj_type, unsigned int * vobj_vaddr); 49 void giet_exit(); 69 50 unsigned int giet_rand(); 70 unsigned int giet_ctx_switch(); 51 unsigned int giet_context_switch(); 52 unsigned int giet_task_id(); 71 53 unsigned int giet_procnumber(); 72 54 73 55 #endif 74 56 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 4 4 // GCC requires this function. Taken from MutekH. 5 5 //////////////////////////////////////////////////////////////////////////////////////// 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) ) 6 void * 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) ) { 11 10 while (size > 3) { 12 11 *dst++ = *src++; 13 12 size -= 4; 14 13 } 14 } 15 15 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; 18 18 19 19 while (size--) { … … 23 23 } 24 24 25 25 26 //////////////////////////////////////////////////////////////////////////////////////// 26 27 // memset() 27 28 // GCC requires this function. Taken from MutekH. 28 29 //////////////////////////////////////////////////////////////////////////////////////// 29 void * memset(void * dst, int s, unsigned int count)30 { 31 char *a = (char *) dst; 32 while (count--) 33 *a++ = (char)s; 34 30 void * memset(void * dst, int s, unsigned int count) { 31 char * a = (char *) dst; 32 while (count--) { 33 *a++ = (char) s; 34 } 35 return dst; 35 36 } 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 9 9 #define _UTILS_H 10 10 11 void* memcpy( void* dst, 12 void* src, 13 unsigned int size ); 11 void * memcpy(void * dst, void * src, unsigned int size); 12 void * memset(void * dst, int s, unsigned int count); 14 13 15 void * memset( void *dst,16 int s,17 unsigned int count);18 14 #endif 19 15 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.