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

Last change on this file since 228 was 228, checked in by meunier, 11 years ago

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.

File size: 2.3 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    unsigned int * dst = _dst;
20    const unsigned int * src = _src;
21
22    /* if source and destination buffer are word-aligned,
23     * then copy word-by-word */
24    if (!((unsigned int)dst & 3) && !((unsigned int)src & 3)) {
25        while (size > 3) {
26            *dst++ = *src++;
27            size -= 4;
28        }
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
42//////////////////////////////////////////////////////////
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;
49}
50
51
52/**
53  the same as the C assert.
54  Taken from Mutekh(SRL API)
55  */
56#define assert(expr)                                                    \
57    do {                                                                \
58        if ( ! (expr) ) {                                                \
59            giet_tty_printf("assertion (%s) failed on %s:%d !\n",  \
60#expr, __FILE__, __LINE__ );                    \
61            __abort();                                                \
62        }                                                                \
63    } while(0)
64
65/**
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);
72}
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
Note: See TracBrowser for help on using the repository browser.