| [175] | 1 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| [178] | 2 | // File : common.h |
|---|
| 3 | // Date : 20/07/2012 |
|---|
| 4 | // Maintener : mohamed karaoui |
|---|
| [175] | 5 | // Copyright (c) UPMC-LIP6 |
|---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 7 | |
|---|
| 8 | #ifndef _COMMON_H_ |
|---|
| 9 | #define _COMMON_H_ |
|---|
| 10 | |
|---|
| [178] | 11 | /* |
|---|
| 12 | * memcpy, memset function |
|---|
| 13 | * This function is required because it can be gnerated by GCC |
|---|
| 14 | * during compilation so we must provide it. |
|---|
| 15 | * Code taken from MutekH. |
|---|
| 16 | */ |
|---|
| 17 | ////////////////////////////////////////////////////////////////////////// |
|---|
| [228] | 18 | static inline void * memcpy(void * _dst, const void * _src, unsigned int size) { |
|---|
| 19 | unsigned int * dst = _dst; |
|---|
| 20 | const unsigned int * src = _src; |
|---|
| [178] | 21 | |
|---|
| 22 | /* if source and destination buffer are word-aligned, |
|---|
| 23 | * then copy word-by-word */ |
|---|
| [228] | 24 | if (!((unsigned int)dst & 3) && !((unsigned int)src & 3)) { |
|---|
| [178] | 25 | while (size > 3) { |
|---|
| 26 | *dst++ = *src++; |
|---|
| 27 | size -= 4; |
|---|
| 28 | } |
|---|
| [228] | 29 | } |
|---|
| [178] | 30 | |
|---|
| [228] | 31 | unsigned char * cdst = (unsigned char *) dst; |
|---|
| 32 | unsigned char * csrc = (unsigned char *) src; |
|---|
| [178] | 33 | |
|---|
| 34 | /* byte-by-byte copy */ |
|---|
| 35 | while (size--) { |
|---|
| 36 | *cdst++ = *csrc++; |
|---|
| 37 | } |
|---|
| 38 | return _dst; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| [228] | 41 | |
|---|
| [178] | 42 | ////////////////////////////////////////////////////////// |
|---|
| [228] | 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; |
|---|
| [178] | 49 | } |
|---|
| 50 | |
|---|
| [228] | 51 | |
|---|
| [175] | 52 | /** |
|---|
| [228] | 53 | the same as the C assert. |
|---|
| 54 | Taken from Mutekh(SRL API) |
|---|
| 55 | */ |
|---|
| 56 | #define assert(expr) \ |
|---|
| 57 | do { \ |
|---|
| 58 | if ( ! (expr) ) { \ |
|---|
| [175] | 59 | giet_tty_printf("assertion (%s) failed on %s:%d !\n", \ |
|---|
| [228] | 60 | #expr, __FILE__, __LINE__ ); \ |
|---|
| 61 | __abort(); \ |
|---|
| 62 | } \ |
|---|
| [175] | 63 | } while(0) |
|---|
| 64 | |
|---|
| 65 | /** |
|---|
| [228] | 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); |
|---|
| [176] | 72 | } |
|---|
| [175] | 73 | |
|---|
| 74 | #endif /* _COMMON_H_ */ |
|---|
| [228] | 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 | |
|---|