Subversion Repositories HelenOS

Rev

Rev 3022 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3022 Rev 4242
1
/*
1
/*
2
 *  The PCI Library -- System-Dependent Stuff
2
 *  The PCI Library -- System-Dependent Stuff
3
 *
3
 *
4
 *  Copyright (c) 1997--2004 Martin Mares <mj@ucw.cz>
4
 *  Copyright (c) 1997--2004 Martin Mares <mj@ucw.cz>
5
 *
5
 *
6
 *  May 8, 2006 - Modified and ported to HelenOS by Jakub Jermar.
6
 *  May 8, 2006 - Modified and ported to HelenOS by Jakub Jermar.
7
 *
7
 *
8
 *  Can be freely distributed and used under the terms of the GNU GPL.
8
 *  Can be freely distributed and used under the terms of the GNU GPL.
9
 */
9
 */
10
 
10
 
11
#ifdef __GNUC__
11
#ifdef __GNUC__
12
#define UNUSED __attribute__((unused))
12
#define UNUSED __attribute__((unused))
13
#define NONRET __attribute__((noreturn))
13
#define NONRET __attribute__((noreturn))
14
#else
14
#else
15
#define UNUSED
15
#define UNUSED
16
#define NONRET
16
#define NONRET
17
#define inline
17
#define inline
18
#endif
18
#endif
19
 
19
 
20
typedef u8 byte;
20
typedef u8 byte;
21
typedef u16 word;
21
typedef u16 word;
22
 
22
 
-
 
23
static inline void swap(u8 *x, u8 *y)
-
 
24
{
-
 
25
    u8 z = *x;
-
 
26
    *x = *y;
-
 
27
    *y = z;
-
 
28
}
-
 
29
 
-
 
30
static inline u16 invert_endianess_16(u16 x)
-
 
31
{
-
 
32
    u8 *px = (u8 *)&x;
-
 
33
    swap(&px[0], &px[1]);
-
 
34
    return x;
-
 
35
}
-
 
36
 
-
 
37
static inline u32 invert_endianess_32(u32 x)
-
 
38
{
-
 
39
    u8 *px = (u8 *)&x;
-
 
40
    swap(&px[0], &px[3]);
-
 
41
    swap(&px[1], &px[2]);
-
 
42
    return x;
-
 
43
}
-
 
44
 
-
 
45
#ifdef UARCH_sparc64
-
 
46
    #define cpu_to_le16(x) (invert_endianess_16(x))
-
 
47
    #define cpu_to_le32(x) (invert_endianess_32(x))
-
 
48
    #define le16_to_cpu(x) (invert_endianess_16(x))
-
 
49
    #define le32_to_cpu(x) (invert_endianess_32(x))
-
 
50
#else
23
#define cpu_to_le16(x) (x)
51
    #define cpu_to_le16(x) (x)
24
#define cpu_to_le32(x) (x)
52
    #define cpu_to_le32(x) (x)
25
#define le16_to_cpu(x) (x)
53
    #define le16_to_cpu(x) (x)
26
#define le32_to_cpu(x) (x)
54
    #define le32_to_cpu(x) (x)
-
 
55
#endif 
27
 
56