1 | /** |
---|
2 | * @file rtems/score/address.inl |
---|
3 | * |
---|
4 | * This include file contains the bodies of the routines |
---|
5 | * about addresses which are inlined. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_ADDRESS_H |
---|
20 | # error "Never use <rtems/score/address.inl> directly; include <rtems/score/address.h> instead." |
---|
21 | #endif |
---|
22 | |
---|
23 | #ifndef _RTEMS_SCORE_ADDRESS_INL |
---|
24 | #define _RTEMS_SCORE_ADDRESS_INL |
---|
25 | |
---|
26 | /** |
---|
27 | * @addtogroup ScoreAddress |
---|
28 | * @{ |
---|
29 | */ |
---|
30 | |
---|
31 | /** @brief Add Offset to Address |
---|
32 | * |
---|
33 | * This function is used to add an @a offset to a @a base address. |
---|
34 | * It returns the resulting address. This address is typically |
---|
35 | * converted to an access type before being used further. |
---|
36 | * |
---|
37 | * @param[in] base is the base address. |
---|
38 | * @param[in] offset is the offset to add to @a base. |
---|
39 | * |
---|
40 | * @return This method returns the resulting address. |
---|
41 | */ |
---|
42 | #include <rtems/bspIo.h> |
---|
43 | RTEMS_INLINE_ROUTINE void *_Addresses_Add_offset ( |
---|
44 | void *base, |
---|
45 | intptr_t offset |
---|
46 | ) |
---|
47 | { |
---|
48 | return (void *)((intptr_t)base + offset); |
---|
49 | } |
---|
50 | |
---|
51 | /** @brief Subtract Offset from Offset |
---|
52 | * |
---|
53 | * This function is used to subtract an @a offset from a @a base |
---|
54 | * address. It returns the resulting address. This address is |
---|
55 | * typically converted to an access type before being used further. |
---|
56 | * |
---|
57 | * @param[in] base is the base address. |
---|
58 | * @param[in] offset is the offset to subtract to @a base. |
---|
59 | * |
---|
60 | * @return This method returns the resulting address. |
---|
61 | */ |
---|
62 | |
---|
63 | RTEMS_INLINE_ROUTINE void *_Addresses_Subtract_offset ( |
---|
64 | void *base, |
---|
65 | intptr_t offset |
---|
66 | ) |
---|
67 | { |
---|
68 | return (void *)((intptr_t)base - offset); |
---|
69 | } |
---|
70 | |
---|
71 | /** @brief Subtract Two Offsets |
---|
72 | * |
---|
73 | * This function is used to subtract two addresses. It returns the |
---|
74 | * resulting offset. |
---|
75 | * |
---|
76 | * @param[in] left is the address on the left hand side of the subtraction. |
---|
77 | * @param[in] right is the address on the right hand side of the subtraction. |
---|
78 | * |
---|
79 | * @return This method returns the resulting address. |
---|
80 | * |
---|
81 | * @note The cast of an address to an uint32_t makes this code |
---|
82 | * dependent on an addresses being thirty two bits. |
---|
83 | */ |
---|
84 | RTEMS_INLINE_ROUTINE uint32_t _Addresses_Subtract ( |
---|
85 | void *left, |
---|
86 | void *right |
---|
87 | ) |
---|
88 | { |
---|
89 | return ((char *) left - (char *) right); |
---|
90 | } |
---|
91 | |
---|
92 | /** @brief Is Address Aligned |
---|
93 | * |
---|
94 | * This function returns TRUE if the given address is correctly |
---|
95 | * aligned for this processor and FALSE otherwise. Proper alignment |
---|
96 | * is based on correctness and efficiency. |
---|
97 | * |
---|
98 | * @param[in] address is the address being checked for alignment. |
---|
99 | * |
---|
100 | * @return This method returns TRUE if the address is aligned and |
---|
101 | * FALSE otherwise. |
---|
102 | */ |
---|
103 | RTEMS_INLINE_ROUTINE bool _Addresses_Is_aligned ( |
---|
104 | void *address |
---|
105 | ) |
---|
106 | { |
---|
107 | #if (CPU_ALIGNMENT == 0) |
---|
108 | return TRUE; |
---|
109 | #else |
---|
110 | return (((uintptr_t)address % CPU_ALIGNMENT) == 0); |
---|
111 | #endif |
---|
112 | } |
---|
113 | |
---|
114 | /** @brief Is Address In Range |
---|
115 | * |
---|
116 | * This function returns TRUE if the given address is within the |
---|
117 | * memory range specified and FALSE otherwise. base is the address |
---|
118 | * of the first byte in the memory range and limit is the address |
---|
119 | * of the last byte in the memory range. The base address is |
---|
120 | * assumed to be lower than the limit address. |
---|
121 | * |
---|
122 | * @param[in] address is the address to check. |
---|
123 | * @param[in] base is the lowest address of the range to check against. |
---|
124 | * @param[in] limit is the highest address of the range to check against. |
---|
125 | * |
---|
126 | * @return This method returns TRUE if the given @a address is within the |
---|
127 | * memory range specified and FALSE otherwise. |
---|
128 | */ |
---|
129 | RTEMS_INLINE_ROUTINE bool _Addresses_Is_in_range ( |
---|
130 | void *address, |
---|
131 | void *base, |
---|
132 | void *limit |
---|
133 | ) |
---|
134 | { |
---|
135 | return (address >= base && address <= limit); |
---|
136 | } |
---|
137 | |
---|
138 | /**@}*/ |
---|
139 | |
---|
140 | #endif |
---|
141 | /* end of include file */ |
---|