source: soft/giet_vm/libs/common.h @ 178

Last change on this file since 178 was 178, checked in by karaoui, 12 years ago

updating libs.

File size: 1.9 KB
Line 
1//////////////////////////////////////////////////////////////////////////////////
2// File         : common.h         
3// Date         : 20/07/2012
4// Maintener    : mohamed karaoui
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7
8#ifndef _COMMON_H_
9#define _COMMON_H_
10
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//////////////////////////////////////////////////////////////////////////
18static inline void *memcpy(void *_dst, const void *_src, unsigned int size)
19{
20    unsigned int *dst = _dst;
21    const unsigned int *src = _src;
22
23    /* if source and destination buffer are word-aligned,
24     * then copy word-by-word */
25    if (!((unsigned int)dst & 3) && !((unsigned int)src & 3))
26        while (size > 3) {
27            *dst++ = *src++;
28            size -= 4;
29        }
30
31    unsigned char *cdst = (unsigned char*)dst;
32    unsigned char *csrc = (unsigned char*)src;
33
34    /* byte-by-byte copy */
35    while (size--) {
36        *cdst++ = *csrc++;
37    }
38    return _dst;
39}
40
41//////////////////////////////////////////////////////////
42static 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;
48}
49
50/**
51   the same as the C assert.
52   Taken from Mutekh(SRL API)
53 */
54#define assert(expr)                                                                                                \
55    do {                                                                                                                                \
56        if ( ! (expr) ) {                                                                                               \
57            giet_tty_printf("assertion (%s) failed on %s:%d !\n",  \
58                                                   #expr, __FILE__, __LINE__ );                                 \
59            __abort();                                                                                          \
60        }                                                                                                                               \
61    } while(0)
62
63/**
64   @this aborts the current execution.
65   Taken from Mutekh(SRL API)
66 */
67static inline void __abort()
68{
69        asm volatile ("break 0");
70        while(1);
71}
72
73#endif /* _COMMON_H_ */
Note: See TracBrowser for help on using the repository browser.